Skip to content

Commit 2b526b3

Browse files
authored
Enforce -release 8 base compilation target (#2250)
Set -release 8 base compilation target Restructured the compile phases in the POM so that when executing on Java 9+, the base classes are compiled with -release 8. This ensures that the bootstrap class path uses the Java 8 API, and so the produced jar is binary compat with Java 8. When built on Java 8, the original source and target (vs release) are used. Fixes an issue where when running on Java 8 (but built on Java9+), `java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;` would be thrown in ControllableInputStream buffering up, because the return expected `Buffer`, not the binary incompatible `ByteBuffer`.
1 parent 515423d commit 2b526b3

File tree

2 files changed

+50
-12
lines changed

2 files changed

+50
-12
lines changed

CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
"name". [2241](https://github.com/jhy/jsoup/issues/2241)
3434
* In `Connection`, skip cookies that have no name, rather than throwing a validation
3535
exception. [2242](https://github.com/jhy/jsoup/issues/2242)
36+
* When running on JDK 1.8, the error `java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;`
37+
could be thrown when parsing from a URL and the buffer size was
38+
exceeded. [2250](https://github.com/jhy/jsoup/pull/2250)
3639

3740
## 1.18.3 (2024-Dec-02)
3841

pom.xml

+47-12
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,27 @@
3838

3939
<build>
4040
<plugins>
41-
<!-- Compile -->
4241
<plugin>
4342
<groupId>org.apache.maven.plugins</groupId>
4443
<artifactId>maven-compiler-plugin</artifactId>
4544
<version>3.13.0</version>
4645
<configuration>
4746
<encoding>UTF-8</encoding>
47+
<useIncrementalCompilation>false</useIncrementalCompilation>
4848
<compilerArgs>
49-
<!-- saves output for package-info.java, so mvn sees it has completed it, so incremental compile works -->
5049
<arg>-Xpkginfo:always</arg>
5150
</compilerArgs>
52-
<!-- this means incremental = true... -->
53-
<useIncrementalCompilation>false</useIncrementalCompilation>
5451
</configuration>
5552
<executions>
53+
<!-- Disable the default compile, so the profiles activated below execute -->
5654
<execution>
57-
<id>compile-java-8</id>
58-
<configuration>
59-
<source>1.8</source>
60-
<target>1.8</target>
61-
</configuration>
55+
<id>default-compile</id>
56+
<phase>none</phase>
57+
</execution>
58+
<execution>
59+
<id>default-testCompile</id>
60+
<phase>none</phase>
6261
</execution>
63-
<!-- There is a JDK 9+ profile execution below, which adds multi-release=true and compiles module-info -->
6462
</executions>
6563
</plugin>
6664

@@ -83,7 +81,6 @@
8381
<version>1.0</version>
8482
</signature>
8583
<ignores>
86-
<ignore>java.nio.ByteBuffer</ignore> <!-- .flip(); added in API1; possibly due to .flip previously returning Buffer, later ByteBuffer; return unused -->
8784
<ignore>java.net.HttpURLConnection</ignore><!-- .setAuthenticator(java.net.Authenticator) in Java 9; only used in multirelease 9+ version -->
8885
</ignores>
8986
</configuration>
@@ -292,7 +289,7 @@
292289
<excludes>
293290
<!-- <exclude>@java.lang.Deprecated</exclude> -->
294291
<exclude>org.jsoup.UncheckedIOException</exclude>
295-
<exlude>org.jsoup.nodes.Element</exlude> <!-- forEach previously deprecated -->
292+
<exclude>org.jsoup.nodes.Element</exclude> <!-- forEach previously deprecated -->
296293
</excludes>
297294
<overrideCompatibilityChangeParameters>
298295
<!-- allows new default and move to default methods. compatible as long as existing binaries aren't making calls via reflection. if so, they need to catch errors anyway. -->
@@ -345,6 +342,36 @@
345342
</distributionManagement>
346343

347344
<profiles>
345+
<!-- Profile for Java 8 -->
346+
<profile>
347+
<id>java-8</id>
348+
<activation>
349+
<jdk>1.8</jdk>
350+
</activation>
351+
<build>
352+
<plugins>
353+
<plugin>
354+
<groupId>org.apache.maven.plugins</groupId>
355+
<artifactId>maven-compiler-plugin</artifactId>
356+
<executions>
357+
<execution>
358+
<id>compile</id>
359+
<phase>compile</phase>
360+
<goals>
361+
<goal>compile</goal>
362+
<goal>testCompile</goal>
363+
</goals>
364+
<configuration>
365+
<source>1.8</source>
366+
<target>1.8</target>
367+
</configuration>
368+
</execution>
369+
</executions>
370+
</plugin>
371+
</plugins>
372+
</build>
373+
</profile>
374+
348375
<!-- Compiles the multi-release jar when executed on JDK9+ -->
349376
<profile>
350377
<id>compile-multi-release</id>
@@ -357,12 +384,19 @@
357384
<groupId>org.apache.maven.plugins</groupId>
358385
<artifactId>maven-compiler-plugin</artifactId>
359386
<executions>
387+
360388
<execution>
361389
<id>compile-java-8</id>
390+
<phase>compile</phase>
391+
<goals>
392+
<goal>compile</goal>
393+
<goal>testCompile</goal>
394+
</goals>
362395
<configuration>
363396
<release>8</release>
364397
</configuration>
365398
</execution>
399+
366400
<execution>
367401
<id>compile-java-9</id>
368402
<phase>compile</phase>
@@ -377,6 +411,7 @@
377411
<multiReleaseOutput>true</multiReleaseOutput>
378412
</configuration>
379413
</execution>
414+
380415
</executions>
381416
</plugin>
382417
</plugins>

0 commit comments

Comments
 (0)