javac: invalid flag: -Xlint:-sunapi | JDK 9
Asked Answered
F

1

5

Arguments passed to javac are as follows:

[javac] Using modern compiler
[javac] Compilation arguments:
[javac] '-deprecation'
[javac] '-d'
[javac] '..'
[javac] '-classpath'
[javac] '..'
[javac] '-sourcepath'
[javac] '..'
[javac] '-g'
[javac] '-XDenableSunApiLintControl'
[javac] '-Xlint:-sunapi'

Which results in error:

[javac] javac: invalid flag: -Xlint:-sunapi

Passing -XDenableSunApiLintControl -Xlint:-sunapi do work with JDK 8 and below. How do I get this to work with Java 9?


Note: classpaths are removed for brevity.

Fondue answered 6/3, 2018 at 15:47 Comment(0)
L
0

It isn't possible to use -Xlint: to configure those diagnostics on Java 9 and newer, the change that removed support for -XDenableSunApiLintControl was https://bugs.openjdk.org/browse/JDK-8148808

For an example like

class T {
  sun.misc.Unsafe theUnsafe;
}

There isn't a supported way to suppress the diagnostic:

$ javac T.java
T.java:2: warning: Unsafe is internal proprietary API and may be removed in a future release
  sun.misc.Unsafe theUnsafe;
          ^
1 warning

The preferred solution is to migrate off the internal APIs. The is the preferred option, and may become mandatory in a future JDK version when the internal APIs are removed: JEP 471: Deprecate the Memory-Access Methods in sun.misc.Unsafe for Removal

Lilllie answered 24/5 at 17:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.