61

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.

Flow
  • 23,572
  • 15
  • 99
  • 156
Steve McLeod
  • 51,737
  • 47
  • 128
  • 184
  • 1
    @NandkumarTekale I don't know, I'm not using Eclipse. I'm compiling from a shell script using Oracle's Java compiler. – Steve McLeod Dec 13 '12 at 08:34
  • possible duplicate of [Cannot stop ant from generating compiler warnings](http://stackoverflow.com/questions/9613857/cannot-stop-ant-from-generating-compiler-warnings) – Ciro Santilli OurBigBook.com May 01 '15 at 11:34
  • Rather than suppress the warning, in the base of the Base64 encoder, why not [use the Java 8 supplied encoder rather than the proprietary API](https://stackoverflow.com/questions/13109588/base64-encoding-in-java)? – Raedwald Jun 04 '19 at 11:13

7 Answers7

54

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.

Community
  • 1
  • 1
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • 3
    It is not true now (jdk7+), see this answer http://stackoverflow.com/questions/13855700/suppress-javac-warning-is-internal-proprietary-api-and-may-be-removed-in-a-f/42406330#42406330 – William Leung Feb 23 '17 at 03:16
  • 2
    It still works with Java 8, but not with Java 9. Has anyone found a solution working with latest Java 9 build? – vip May 25 '17 at 10:57
  • I was able to get rid of it with this: https://stackoverflow.com/a/34966719/714112 – Sridhar Sarnobat Oct 05 '20 at 23:50
26

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>
Brandon
  • 2,367
  • 26
  • 32
  • 1
    This doesn't seem to work for me. Any ideas why not? – LadyCailin Mar 08 '16 at 17:59
  • 1
    It works for me using Oracle's Java 8 compiler. I just verified with a single-file project that it reported a warning without the configuration above, and then the warning went away after I added the section above. My answer isn't explicit about this, but did you put that section inside `build`:`plugins`? Otherwise, I don't have any other ideas. – Brandon Mar 08 '16 at 19:24
  • Actually, after further inspection, it appears to be coming from the maven-processor-plugin: maven-processor-plugin:2.2.4:process (process) @ project --- diagnostic: /home/project/src/main/java/Test.java:8: warning: sun.misc.Signal is internal proprietary API and may be removed in a future release import sun.misc.Signal; – LadyCailin Mar 08 '16 at 19:27
  • 1
    Setting outputDiagnostics to false fixes this. Similar problem referenced here: https://stackoverflow.com/questions/22634008/maven-processor-plugin-to-ignore-undefined-symbols – LadyCailin Mar 08 '16 at 19:46
  • Thanks for the info! I'm glad you found a fix. – Brandon Mar 09 '16 at 16:07
  • 8
    for these cases when this does not work, just add `true` to the configuration – Alain Pannetier Aug 21 '16 at 12:34
  • Can you please tell me which plugin I can add for the ivy.xml file. – Pardha Saradhi Mar 06 '20 at 07:11
18

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
William Leung
  • 1,556
  • 17
  • 26
8

Reference its interface CachedRowSet not the implementation.

Boris Pavlović
  • 63,078
  • 28
  • 122
  • 148
3

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.

Steve McLeod
  • 51,737
  • 47
  • 128
  • 184
2

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

0

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.

Jakub Zaverka
  • 8,816
  • 3
  • 32
  • 48