Cannot stop ant from generating compiler Sun proprietary API warnings

前端 未结 6 890
栀梦
栀梦 2020-12-07 01:13

I call javac from my ant script like this:



        
相关标签:
6条回答
  • 2020-12-07 01:21

    You cannot do that: Neither from the command line, so you cannot do it from Ant either.

    The javac documentation says:

    -Xlint:none

    Disable all warnings not mandated by the Java Language Specification.

    So it seems this kind of warning cannot be suppressed, because they are raised by the JLS directly.

    What you can do is to:

    1. use @SuppressWarnings({"deprecation"}, {"unchecked"}) at the required positions
    2. use some workaround to redirect the warning messages to /dev/null
    3. try compiling from the command line with the -Xlint:-unchecked -Xlint:-deprecation arguments, maybe it is only an Ant-related issue.
    0 讨论(0)
  • 2020-12-07 01:31

    adding the -XDignore.symbol.file option to the javac command line worked for me.

    0 讨论(0)
  • 2020-12-07 01:37

    To prevent deprecation warnings I tried to do it using JDK 6 and JDK 7.

    With JDK 7, @Deprecated annotation does the work

    With JDK 6, it does not work, neither adding -Xlint:-deprecation param works for me. The only way I managed to remove the warning was using the @deprecated Javadoc Tag:

      /**
       * @deprecated
       */
      @Override
      public void removeValue(String arg0) {
        // TODO Auto-generated method stub
      }
    
    0 讨论(0)
  • 2020-12-07 01:41

    use nowarn attribute see below

    e.g.

    <javac srcdir="src" 
       destdir="build/classes" source="1.6" 
       target="1.6" debug="true" encoding="Cp1252"
       nowarn="on">
    

    by default nowarn attribute is off

    0 讨论(0)
  • 2020-12-07 01:42

    The best way to do this is to use the sunapi suppression, i.e. either -Xlint:-sunapi for the entire compile, or @SuppressWarnings("sunapi") at your required scope.

    Note, the only way to use this suppression though, is to first enable it with the compiler option -XDenableSunApiLintControl

    enableSunApiLintControl

    0 讨论(0)
  • 2020-12-07 01:42

    Recommendation: Don't ignore your compiler's warnings. The warnings are there for a reason. My company's legacy codebase is moving towards a "treat warnings as errors and fail the build" model as we can expend the effort to fix warnings produced during our compile cycle.

    In your case, the warning is:

    warning: sun.reflect.Reflection is Sun proprietary API and may be removed in a future release
    

    It has always been a warning to not import from sun packages as long as I can remember, because they're a non-public API. There's even a FAQ about it on the official Oracle Java site.

    You haven't posted your actual code, so it's hard to provide further recommendations...What are you using in sun.reflect.Reflection that you couldn't also do through something in java.lang.reflect?

    0 讨论(0)
提交回复
热议问题