[
https://issues.apache.org/jira/browse/HTTPCORE-802?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18123035#comment-18123035
]
Ryan Schmitt commented on HTTPCORE-802:
---------------------------------------
These compilation failures are caused by a bug in the JDK:
[https://bugs.openjdk.org/browse/JDK-8365060]
This doesn't make them any less annoying, but at least it's a straight answer
to the question "why isn't this working?"
There are a few options here:
# Cross-compile with {{-source}} and {{-target}}, rather than {{-release}}.
# Don't cross-compile. Use Maven toolchain support to both compile for and
test on a particular Java version. (This is the option I went with when I
reworked the build logic in March of this year, with the toolchain version
controlled by {{hc.build.toolchain.version}}, e.g. {{./mvnw
-Dhc.build.toolchain.version=21}}.)
# Enable cross-compilation by using reflection to access
{{jdk.net.ExtendedSocketOptions}}.
In theory, approach #2 means that there's nothing to "validate," because we
build for JDK8 by using an actual JDK8 toolchain, rather than cross-compilation
from a newer JDK. (In fact, the {{-release}} flag doesn't even exist on JDK8.)
So if that option has already been disabled, then there isn't necessarily any
further action required here.
> jdk.net.ExtendedSocketOptions causes compatibility problems with newer JDKs
> ---------------------------------------------------------------------------
>
> Key: HTTPCORE-802
> URL: https://issues.apache.org/jira/browse/HTTPCORE-802
> Project: HttpComponents HttpCore
> Issue Type: Improvement
> Reporter: Oleg Kalnichevski
> Priority: Major
>
> jdk.net.ExtendedSocketOptions causes compatibility problems with newer JDKs
> when using Java 8 as a release target (--release compile option).
> Newer JDKs fail to import jdk.net package when targeting Java 8 apparently
> due this feature being considered invalid for Java 8
> {noformat}
> $ mvn -v
> Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937)
> Maven home: /home/oleg/opt/maven
> Java version: 17.0.17, vendor: Amazon.com Inc., runtime:
> /home/oleg/opt/amazon-corretto-17.0.17.10.1
> Default locale: en_US, platform encoding: UTF-8
> OS name: "linux", version: "6.12.107+deb13-amd64", arch: "amd64", family:
> "unix"
> {noformat}
> {noformat}
> $ mvn clean compile -P-use-toolchains -DjavaVersion=8
> {noformat}
> {noformat}
> [INFO] --- compiler:3.16.0:compile (default-compile) @ httpcore5 ---
> [INFO] Recompiling the module because of changed source code.
> [INFO] Compiling 570 source files with javac [debug deprecation release 8] to
> target/classes
> [INFO] -------------------------------------------------------------
> [ERROR] COMPILATION ERROR :
> [INFO] -------------------------------------------------------------
> [ERROR]
> /home/oleg/src/apache.org/httpcomponents/httpcore/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java:[52,15]
> package jdk.net does not exist
> [ERROR]
> /home/oleg/src/apache.org/httpcomponents/httpcore/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java:[48,15]
> package jdk.net does not exist
> [ERROR]
> /home/oleg/src/apache.org/httpcomponents/httpcore/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java:[49,15]
> package jdk.net does not exist
> [ERROR]
> /home/oleg/src/apache.org/httpcomponents/httpcore/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java:[44,15]
> package jdk.net does not exist
> [ERROR]
> /home/oleg/src/apache.org/httpcomponents/httpcore/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java:[45,15]
> package jdk.net does not exist
> [ERROR]
> /home/oleg/src/apache.org/httpcomponents/httpcore/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequestListener.java:[41,15]
> package jdk.net does not exist
> [ERROR]
> /home/oleg/src/apache.org/httpcomponents/httpcore/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequestListener.java:[42,15]
> package jdk.net does not exist
> [ERROR]
> /home/oleg/src/apache.org/httpcomponents/httpcore/httpcore5/src/main/java/org/apache/hc/core5/util/ReflectionUtils.java:[30,15]
> package jdk.net does not exist
> [ERROR]
> /home/oleg/src/apache.org/httpcomponents/httpcore/httpcore5/src/main/java/org/apache/hc/core5/util/ReflectionUtils.java:[31,15]
> package jdk.net does not exist
> [ERROR]
> /home/oleg/src/apache.org/httpcomponents/httpcore/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java:[334,41]
> cannot find symbol
> {noformat}
> When using the same JDK and targeting Java 11, the same code compiles
> successfully
> {noformat}
> mvn clean compile -P-use-toolchains -DjavaVersion=11
> {noformat}
> {noformat}
>
> [INFO] --- compiler:3.16.0:compile (default-compile) @ httpcore5 ---
> [INFO] Recompiling the module because of changed source code.
> [INFO] Compiling 570 source files with javac [debug deprecation release 11]
> to target/classes
> ...
> [INFO] Reactor Summary for Apache HttpComponents Core 5.5-beta4-SNAPSHOT:
> [INFO]
> [INFO] Apache HttpComponents Core ......................... SUCCESS [ 1.089
> s]
> [INFO] Apache HttpComponents Core HTTP/1.1 ................ SUCCESS [ 9.346
> s]
> [INFO]
> {noformat}
> I had to disable release target validation due to this problem when upgrading
> our maven POM. Please note the check was not used prior to the upgrade.
> Given that the animal sniffer plugin has been discontinued in favor of JDK
> release target validation, we have lost a valuable quality control mechanism
> and a safe-guard.
> The best course of action would be just upgrade to Java 17 and forget about
> Java 8 compatibility woes.
> Alternatively, we could consider removing direct import of jdk.net classes
> and go back to using reflection.
> Oleg
>
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]