Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress javac warning "...is internal proprietary API and may be removed in a future release"

Tags:

java

javac

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.


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>

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 without any warnings

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

Reference its interface CachedRowSet not the implementation.


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.


I acknowledge that this answer is a late harvest, and you will have solved your problem. But I got stuck in the same problem as you, and researching I found this solution.

Why happens?

https://www.oracle.com/java/technologies/faq-sun-packages.html

Is this behavior wrong?

No, its a warning telling us that ChachedRowSetImpl does not belong to the public interface, therefore compatibility is not guaranteed.

Workaround

The following code snippet creates a CachedRowSet object by using a RowSetFactory which is created by the RowSetProvider:

RowSetFactory factory = RowSetProvider.newFactory();
CachedRowSet rowset = factory.createCachedRowSet();

This creates a CachedRowSet object from the implementation class com.sun.rowset.CachedRowSetImpl. It’s equivalent to the following statement:

CachedRowSet rowset = new com.sun.rowset.CachedRowSetImpl();

However, it’s recommended to create a CachedRowSet object from a RowSetFactory because the reference implementation may be changed in future