user2780757
user2780757

Reputation: 191

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.

Upvotes: 0

Views: 6195

Answers (2)

apangin
apangin

Reputation: 98640

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.

Upvotes: 9

Fairoz
Fairoz

Reputation: 1664

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

Upvotes: 4

Related Questions