JDK-8259039 : Passing different version to --release flag than javac version output warning
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 12,14,15,16
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: x86_64
  • Submitted: 2021-01-03
  • Updated: 2021-09-28
  • Resolved: 2021-09-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 18
18 b16Fixed
Description
ADDITIONAL SYSTEM INFORMATION :
Reproducible with standard open jdk 12 on OS X

A DESCRIPTION OF THE PROBLEM :
Compiling the following code in issue reproduction section that uses Sun's internal API (ExtendedOpenOption.DIRECT), with different JDK version passed to --release flag than the javac version,  may generate an un-suppressible (?) Sun internal API warning; but when compiling with the same JDK version passed to --release flag no warning will be emitted.


We would like to understand the following:
1. Is this an expected / specified behavior of --release flag to emit warnings when different versions are used?  (we can't seems to find relevant information in https://openjdk.java.net/jeps/247) 
2. In this specific case, can the internal proprietary API warning be suppressed given it's not produced from -Xlint option?



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Code to be compiled
```
package com.company;

import java.io.IOException;
import java.nio.channels.Channel;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.List;

public class Main {

    @SuppressWarnings({"rawtypes", "unchecked"})
    public static void main(String[] args) throws IOException {
        List words = new ArrayList();
        words.add("hello");

        Channel channel = FileChannel.open(Path.of("blablabla"), StandardOpenOption.CREATE, StandardOpenOption.WRITE,
                                                StandardOpenOption.READ, com.sun.nio.file.ExtendedOpenOption.DIRECT);
        System.out.println(channel.isOpen());
    }
}
```

Compilation with different jdk versions passed into --release flag would generate warning message
```
% export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-12.jdk/Contents/Home
% javac --version
javac 12.0.2
% javac src/com/company/Main.java --release 11                                        
src/com/company/Main.java:19: warning: ExtendedOpenOption is internal proprietary API and may be removed in a future release
                                                StandardOpenOption.READ, com.sun.nio.file.ExtendedOpenOption.DIRECT);
                                                                                         ^
1 warning
```

Compilation with same jdk versions passed into --release flag does NOT generate warning message
```
% export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
% javac --version
javac 11.0.9
% javac src/com/company/Main.java --release 11  
```


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Compilation with different jdk versions passed into --release flag should not generate warning message, since --release flag is not expected to perform lint checking? 
ACTUAL -
Compilation with different jdk versions passed into --release flag would generate warning message

---------- BEGIN SOURCE ----------
package com.company;

import java.io.IOException;
import java.nio.channels.Channel;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.List;

public class Main {

    @SuppressWarnings({"rawtypes", "unchecked"})
    public static void main(String[] args) throws IOException {
        List words = new ArrayList();
        words.add("hello");

        Channel channel = FileChannel.open(Path.of("blablabla"), StandardOpenOption.CREATE, StandardOpenOption.WRITE,
                                                StandardOpenOption.READ, com.sun.nio.file.ExtendedOpenOption.DIRECT);
        System.out.println(channel.isOpen());
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
The workaround to "suppress" the warning message is to use reflection for the internal API.


Comments
Changeset: 699865f7 Author: Jan Lahoda <jlahoda@openjdk.org> Date: 2021-09-20 13:43:14 +0000 URL: https://git.openjdk.java.net/jdk/commit/699865f76cdf76fbd8042c1b5677b71e29faa4bc
20-09-2021

While providing a lower JDK version with --release option in javac, every time it throws a warning, whereas using the --release number with the same JDK build does not throw any warnings.
04-01-2021