简体   繁体   English

在Java代码中设置-noverify标志

[英]Set -noverify flag in java code

I would like to set -noverify as a VM argument through java code. 我想通过Java代码将-noverify设置为VM参数。 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? 如果我使用System.setProperty(..,..) ,该如何设置值或键?

I have tried using System.property("Xverify","none") but this doesn't seem to work. 我尝试使用System.property("Xverify","none")但这似乎不起作用。

Note : This is just to run some test cases. 注意 :这只是为了运行一些测试用例。 I am turning off byte code verification because of this issue - link 由于这个问题,我正在关闭字节码验证- 链接

Thank you. 谢谢。

Let me summarize comments in this answer. 让我总结一下此答案中的评论。

  • It is dangerous to turn the bytecode verification off, especially when you know the application throws VerifyError . 关闭字节码验证很危险,尤其是当您知道应用程序抛出VerifyError This means that the application generates invalid bytecode, and when JVM executes it, the results are unpredictable. 这意味着应用程序生成无效的字节码,并且当JVM执行它时,结果是不可预测的。 For example, JVM may crash like in this question . 例如,JVM可能像这个问题一样崩溃。
  • 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. 您提到的PowerMock问题的链接确认Javassist库中存在错误 The right way to solve the issue is to update to newer Javassist version where this bug has been fixed. 解决此问题的正确方法是更新到已修复此错误的Javassist新版本。

You need to use "-Xverify:none" as vm argument. 您需要使用“ -Xverify:none”作为vm参数。 It is recommended not to use -Xverify:none in production environment. 建议在生产环境中不要使用-Xverify:none。

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. 对于不熟悉字节码验证的用户,这只是JVM的类加载过程的一部分,该过程检查代码是否存在某些危险和不允许的行为。 You can (but shouldn't) disable this protection on many JVMs by adding -Xverify:none 您可以(但不应)通过添加-Xverify:none来在许多JVM上禁用此保护。

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: //blogs.oracle.com/buck/entry/never_disable_bytecode_verification_in

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM