Set -noverify flag in java code

僤鯓⒐⒋嵵緔 提交于 2019-12-12 03:39:24

问题


I would like to set -noverify as a VM argument through java code. I could not find any resource online to help with this.

If I use System.setProperty(..,..) , what do I set as the value or perhaps the key?

I have tried using System.property("Xverify","none") but this doesn't seem to work.

Note: This is just to run some test cases. I am turning off byte code verification because of this issue - link

Thank you.


回答1:


Let me summarize comments in this answer.

  • It is dangerous to turn the bytecode verification off, especially when you know the application throws VerifyError. This means that the application generates invalid bytecode, and when JVM executes it, the results are unpredictable. For example, JVM may crash like in this question.
  • There is no legal way to turn the bytecode verification off programmatically. Otherwise this would be a serious security breach that allows to run unsafe code without explicit permissions.
  • The link to PowerMock issue you've mentioned confirms that there was a bug in Javassist library. The right way to solve the issue is to update to newer Javassist version where this bug has been fixed.



回答2:


You need to use "-Xverify:none" as vm argument. It is recommended not to use -Xverify:none in production environment.

For those of you unfamiliar with bytecode verification, it is simply part of the JVM's classloading process that checks the code for certain dangerous and disallowed behavior. You can (but shouldn't) disable this protection on many JVMs by adding -Xverify:none

Please find the complete details about the side affect of using this flag - https://blogs.oracle.com/buck/entry/never_disable_bytecode_verification_in



来源:https://stackoverflow.com/questions/43559229/set-noverify-flag-in-java-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!