Suppress javac warning “…is internal proprietary A

2019-01-11 15:49发布

When I compile the Spring JDBC source on OS X with JDK 1.7.0, I get this warning:

warning: CachedRowSetImpl is internal proprietary API and may be removed in a future release

How do I suppress the warning message during a compile?

I already know and use Java's @SuppressWarning annotations. I'm looking for the specific use of this to suppress the warning I've described.

My question specifically is, in this line of code:

@SuppressWarnings("valuegoeshere")

what should "valuegoeshere" be replaced with?

EDIT: People, I know that it is best to avoid the code that leads to the warning. And usually that would be my approach. However I'm compiling third-party code here which I don't want to rewrite. I just want to add the correct annotation to suppress the warning, so that warnings I can actually do something about don't get buried.

标签: java javac
6条回答
你好瞎i
2楼-- · 2019-01-11 16:20

If you are using maven, you might be interested in adding the following to your pom.xml file:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <compilerArgument>-XDignore.symbol.file</compilerArgument>
    </configuration>
</plugin>
查看更多
趁早两清
3楼-- · 2019-01-11 16:26

This particular warning cannot be suppressed. At least not officially.

The warning about proprietary API means that you should not use the API which causes the warning. Sun does not support such API and the warning will not be suppressible.

If you're particularly determined, you can use the highly undocumented javac -XDignore.symbol.file flag which will compile your program against Sun's internal rt.jar rather than the public-facing symbol file ct.sym. rt.jar doesn't produce this warning.

查看更多
贪生不怕死
4楼-- · 2019-01-11 16:28

see this answer

Cannot stop ant from generating compiler Sun proprietary API warnings

Testing code

@SuppressWarnings("sunapi")
sun.security.x509.X509CertImpl test;

compiling command line

javac test.java -Werror -Xlint:sunapi -XDenableSunApiLintControl

or

javac test.java -Werror -Xlint:all -XDenableSunApiLintControl

compile passed with no any warning

remove the SuppressWarnings tag and compile again

an error is reported then

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
查看更多
狗以群分
5楼-- · 2019-01-11 16:34

I tried

@SuppressWarnings("all")

but that didn't work.

So I resorted to a horrible, horrible kludge which I don't recommend in general, but in this specific case made the warning go away. I used reflection to instantiate a new instance of the com.sun.rowset.CachedRowSetImpl class.

I replaced this line, which caused the warning:

    return new CachedRowSetImpl();

with this block:

    try {
        final Class<?> aClass = Class.forName("com.sun.rowset.CachedRowSetImpl");
        return (CachedRowSet) aClass.newInstance();
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }

Please don't do this in your own code without first considering any other option.

查看更多
神经病院院长
6楼-- · 2019-01-11 16:36

Try the javac option

-Xlint:none

If you compile from an IDE, it should have an option to disable warnings.

This will disable ALL warnings that are not a part of Java Language Specification. So for example "unchecked" warning will not be blocked.

查看更多
看我几分像从前
7楼-- · 2019-01-11 16:39

Reference its interface CachedRowSet not the implementation.

查看更多
登录 后发表回答