views:

796

answers:

5

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?

+5  A: 

because you cannot disable this warning

dfa
see also JeeBee answer
dfa
+7  A: 

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.

JeeBee
A: 

Encapsulate the call in a class which you place in a library jar on your classpath. Then the warning only shows when that library is recompiled.

Thorbjørn Ravn Andersen
+2  A: 

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.

wolfy
+1  A: 

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)

Cowan