抑制javac警告"......是内部专有API,可能会在将来的版本中删除"

Ste*_*eod 45 java javac

当我使用JDK 1.7.0在OS X上编译Spring JDBC源代码时,我收到此警告:

warning: CachedRowSetImpl is internal proprietary API and may be removed in a future release
Run Code Online (Sandbox Code Playgroud)

如何在编译期间禁止显示警告消息?

我已经知道并使用Java的@SuppressWarning注释.我正在寻找具体用法来抑制我所描述的警告.

我的问题具体是,在这行代码中:

@SuppressWarnings("valuegoeshere")
Run Code Online (Sandbox Code Playgroud)

应该用"valuegoeshere"替换什么?

编辑:人们,我知道最好避免导致警告的代码.通常这将是我的方法.但是我在这里编译第三方代码,我不想重写.我只想添加正确的注释来抑制警告,以便我可以实际做些什么的警告不会被埋没.

Joh*_*ica 46

无法抑制此特定警告.至少不正式.

有关专有API的警告意味着您不应使用导致警告的API.Sun不支持此类API,并且警告不会被禁止.

如果您特别确定,可以使用高度未记录的javac -XDignore.symbol.file标志,该标志将针对Sun的内部rt.jar而不是面向公众的符号文件编译您的程序ct.sym.rt.jar没有产生这个警告.

  • 现在不是真的(jdk7 +),请参阅以下答案http://stackoverflow.com/questions/13855700/suppress-javac-warning-is-internal-proprietary-api-and-may-be-removed-in-af/ 42406330#42406330 (2认同)
  • 它仍适用于Java 8,但不适用于Java 9.有没有人找到使用最新Java 9版本的解决方案? (2认同)

Rea*_*ted 20

如果您使用的是maven,则可能有兴趣将以下内容添加到您的pom.xml文件中:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <compilerArgument>-XDignore.symbol.file</compilerArgument>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

  • 对于这些不起作用的情况,只需在配置中添加`<fork> true </ fork>` (5认同)

Wil*_*ung 11

看到这个答案

无法阻止ant生成编译器Sun专有的API警告

测试代码

@SuppressWarnings("sunapi")
sun.security.x509.X509CertImpl test;
Run Code Online (Sandbox Code Playgroud)

编译命令行

javac test.java -Werror -Xlint:sunapi -XDenableSunApiLintControl
Run Code Online (Sandbox Code Playgroud)

要么

javac test.java -Werror -Xlint:all -XDenableSunApiLintControl
Run Code Online (Sandbox Code Playgroud)

编译通过没有任何警告

删除SuppressWarnings标记并再次编译

然后报告错误

test.java:4: warning: X509CertImpl is internal proprietary API and may be removed in a future release
        sun.security.x509.X509CertImpl test;
                     ^
error: warnings found and -Werror specified
1 error
1 warning
Run Code Online (Sandbox Code Playgroud)


Bor*_*vić 8

引用它的接口CachedRowSet不是实现.

  • 谢谢,但这不可能.为此,我需要编写自己的CachedRowSet实现. (2认同)