Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to hide java 11 Nashorn deprecation warnings

I recently upgraded to Java11. There are 150 new Nashorn deprecation warnings:

Utils.java:31: warning: [removal] NashornScriptEngineFactory in jdk.nashorn.api.scripting has been deprecated and marked for removal
            NashornScriptEngineFactory  factory = new NashornScriptEngineFactory();

Is it possible to hide these deprecation warnings?

What I've tried:

tasks.withType(JavaCompile) {
    options.compilerArgs += '-Xlint:-deprecation'
}

./gradlew build -Dnashorn.option.no.deprecation.warning=true

gradle-wrapper.properties: org.gradle.jvmargs= -Dnashorn.args=--no-deprecation-warning

as well as

NashornScriptEngineFactory  factory = new NashornScriptEngineFactory();
ENGINE = factory.getScriptEngine(new String[] {"--no-java --no-deprecation-warning"}, null, className -> false);

I believe JDK-8210140 may reference a similar problem.

like image 322
Jason Brown Avatar asked Apr 11 '19 21:04

Jason Brown


People also ask

How do you stop a deprecated warning in Java?

You can use the @SuppressWarnings annotation to suppress warnings whenever that code is compiled. Place the @SuppressWarnings annotation at the declaration of the class, method, field, or local variable that uses a deprecated API.

What are deprecation warnings?

Deprecation warnings are a common thing in our industry. They are warnings that notify us that a specific feature (e.g. a method) will be removed soon (usually in the next minor or major version) and should be replaced with something else.


1 Answers

The warning that you are seeing is emitted by the compiler, the --no-deprecation-warning only suppresses the runtime warning "Warning: Nashorn engine is planned to be removed from a future JDK release" that is emitted when creating the script engine instance.

You should be able to use:

@SuppressWarnings("removal")
NashornScriptEngineFactory factory = new NashornScriptEngineFactory();

In the source code to suppress the warning completely.

Or otherwise use:

-Xlint:-removal

As a compiler argument. This will suppress the warnings, but you'll still get a note on a per file basis.

like image 188
Jorn Vernee Avatar answered Oct 02 '22 12:10

Jorn Vernee