How can I suppress java compiler warnings about Sun proprietary API

22,036

Solution 1

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.

Solution 2

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!

Solution 3

because you cannot disable this warning

Solution 4

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)

Solution 5

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.

Share:
22,036
Scott
Author by

Scott

Software developer at Metaswitch Networks. Github: https://github.com/tomdee LinkedIn: http://lnkd.in/jdVRUv

Updated on February 21, 2020

Comments

  • Scott
    Scott over 4 years

    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?

  • Landern
    Landern over 12 years
    Nope, that flag doesn't disable this particular warning.
  • Tim Lewis
    Tim Lewis over 12 years
    Thank you! This is exactly what I need!
  • Tim Lewis
    Tim Lewis over 12 years
    ah but you can switch them off! see Michael Chaves answer!
  • Boann
    Boann over 11 years
    It's worth remembering why the warning exists, and why it's not supposed to be possible to shut it up, not with @SuppressWarnings("all"), or -nowarn or -Xlint:none or -Xmaxwarns 0. If you depend on internal classes your program will break sooner or later. But this is a neat hack when you know what you're doing and the proprietary API warning is just noise clogging the console. Thanks!
  • Robert Niestroj
    Robert Niestroj over 10 years
    Can i just change the import to the Apache Commons version and evertyhing will work the same?