Search code examples
javajvmjvm-arguments

Set -noverify flag in java code


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.


Solution

  • 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.