Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I suppress java compiler warnings about Sun proprietary API [duplicate]

I'm using the encode() method from the sun.misc.BASE64Encoder package. How do I suppress the compiler warnings that it generates?

sun.misc.BASE64Encoder is Sun proprietary API and may be removed in

And as a followup, why don't I see this warning in Eclipse?

like image 786
tomdee Avatar asked Jul 16 '09 10:07

tomdee


People also ask

How do you suppress uses or overrides a deprecated API?

It appears that warning you of the use of deprecated APIs is managed by the language spec. Your best option would be to fix the use of deprecated APIs. However, an option would be to add the @SuppressWarnings("deprecation") annotation to the classes or methods that are using the deprecated APIs.


6 Answers

There is a totally undocumented way to suppress the sun proprietary API warnings! Add -XDignore.symbol.file to the javac command line.

I found this at http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6476630 (scroll all the way to the very last comment). We all need to think kind thoughts about "xfournet" who added that last comment!

like image 160
Michael Chaves Avatar answered Oct 20 '22 06:10

Michael Chaves


You could switch to a different Base64 implementation, e.g., http://commons.apache.org/codec/apidocs/org/apache/commons/codec/binary/Base64.html which is part of the Apache commons packages, which you might already have included in your classpath, or http://iharder.sourceforge.net/current/java/base64/ which you could just take the implementation and stick in your source tree if you don't want another Jar on the path.

like image 23
JeeBee Avatar answered Oct 20 '22 06:10

JeeBee


because you cannot disable this warning

like image 39
dfa Avatar answered Oct 20 '22 05:10

dfa


Eclipse does have a setting which (should) pick this up, see e.g. the desciption in the Eclipse 3.1 release notes:

Preferences → Java → Compiler → Errors/Warnings → Deprecated And Restricted API → Forbidden/Discouraged Reference

(and the project properties page to allow project-specific overrides of this setting)

like image 44
Cowan Avatar answered Oct 20 '22 06:10

Cowan


You can't switch them off, Eclipse simply filters them for you (if told to do so).

Quick interim fix on Linux:

javac *.java 2>&1 | pcregrep -v -M ".*Sun proprietary API.*\n.*\n.*\^"

2>&1 ... puts STDERR into STDOUT, so the pipeline "|" will work

pcregrep might or might not be present on your system - if not, use your package utility (e.g. on Debian, Ubuntu etc: "sudo apt-get install pcregrep")

The expression searches for the "Sun proprietary API" warning and the following two lines (containing the line and the "^" indicating the position of the error in the line).

I leave the "XY warnings." line in at the end, lest I forget there were warnings ;o) Note that if you have other warnings as well, the number reported there will of course not be correct :o)

NOTE also that standard "grep" does not work as well, because it can't span multiple lines.

like image 31
wolfy Avatar answered Oct 20 '22 04:10

wolfy


If you understand the inherent problems with using a proprietary API and decide to do it anyway, and 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>
    <version>2.3.2</version>
    <configuration>
        <compilerArgument>-XDignore.symbol.file</compilerArgument>
    </configuration>
</plugin>
like image 27
Brandon Avatar answered Oct 20 '22 05:10

Brandon