Repository navigation
Repair NoSuchFieldError on Jackson 2.20+, remove javax.activation, upgrade dependencies and tests - #78
Open
sbailliez wants to merge 6 commits into
Open
Repair NoSuchFieldError on Jackson 2.20+, remove javax.activation, upgrade dependencies and tests#78sbailliez wants to merge 6 commits into
sbailliez wants to merge 6 commits into
Conversation
PropertyNamingStrategy.SNAKE_CASE was deprecated in Jackson 2.12 and
removed in Jackson 2.20. With jackson-databind 2.20 or later on the
classpath, creating a Client fails with:
java.lang.NoSuchFieldError: SNAKE_CASE
PropertyNamingStrategies.SNAKE_CASE exists since Jackson 2.12 and gives
the same naming.
8.14.6 is the newest 8.x release. Gradle 9 needs Java 17 or later to run Gradle itself, and the CI builds with JDK 8 and 11, so this change stays on Gradle 8. The wrapper jar matches the published SHA-256 checksum for 8.14.6.
* httpclient and httpmime: 4.5.13 -> 4.5.14 * jackson-databind: 2.16.2 -> 2.22.4 * commons-codec: 1.10 -> 1.23.0 * commons-io: 2.7 -> 2.22.0 * junit: 4.13.1 -> 4.13.2 * mockito-all 1.10.19 -> mockito-core 4.11.0 mockito-all has no release after 1.10.19. mockito-core 4.11.0 is the newest release that runs on Java 8. Mockito 5 needs Java 11, and the CI also builds with JDK 8. Mockito 4 removed org.mockito.Matchers and takes an ArgumentMatcher in argThat(), so FileUploaderTest uses ArgumentMatchers and an ArgumentMatcher in place of a Hamcrest matcher. javax.activation 1.2.0 is the last release of that artifact. It stays as is.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
RequestHelper.getMimeType used javax.activation.MimetypesFileTypeMap. With a Jakarta activation jar on the classpath, this can fail with IllegalAccessError in MimetypesFileTypeMap (issue uploadcare#50). getMimeType now uses the file name table of the JDK, URLConnection.getFileNameMap(), which exists since Java 1.1. The signature does not change, and the default for an unknown or null name is still application/octet-stream. The JDK table knows more types than the default table of javax.activation, so some files get a more exact type. For example, .pdf and .zip now give application/pdf and application/zip in place of application/octet-stream. Remove com.sun.activation:javax.activation from the dependencies. Nothing else in the library uses javax.activation. Fixes uploadcare#50
* junit 4.13.2 -> JUnit Jupiter 6.1.3 (junit-bom) * mockito-core 4.11.0 -> 5.24.0, plus mockito-junit-jupiter 5.24.0 JUnit 6 needs Java 17 to run, so the build uses a JDK 17 toolchain. The library is still compiled with --release 7: JDK 17 is the newest LTS JDK that can do that (JDK 20 removed release 7). The class files in the jar stay at major version 51 (Java 7). The tests compile with --release 17. The foojay resolver plugin downloads JDK 17 when it is not installed. The tests run on JDK 17 by default. -PtestJavaVersion=21 runs them on another JDK. The Mockito agent loads at test JVM start, as the Mockito documentation advises. The CI matrix changes from JDK 8 and 11 to JDK 17 and 21, because JUnit 6 cannot run on JDK 8 or 11. The snapshot and release jobs run Gradle on JDK 17. Test changes: org.junit.jupiter.api, @beforeeach, assertThrows in CdnPathBuilderTest, and MockitoExtension with @mock in CdnPathBuilderTest.
Jackson 2.21 is the long-term support line. 2.22 is a feature line. 2.21.8 is the newest 2.21 patch. OSV lists no advisory for it. The 11 tests pass.
carlspring
approved these changes
Oct 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ClientreadsPropertyNamingStrategy.SNAKE_CASE. Jackson deprecated that field in 2.12 and removed it in 2.20. With the released 3.5.3 jar and jackson-databind 2.20 or later on the classpath, creating aClientfails:Changes
ClientusesPropertyNamingStrategies.SNAKE_CASE. It exists since Jackson 2.12 and gives the same naming. No public API change.Notes:
org.mockito.Matchers, soFileUploaderTestusesArgumentMatchersand anArgumentMatcher.Jakarta EE (issue #50)
RequestHelper.getMimeTypeusedjavax.activation.MimetypesFileTypeMap. With a Jakarta activation jar on the classpath, this can fail withIllegalAccessErrorinMimetypesFileTypeMap(see #50).getMimeTypenow uses the file name table of the JDK,URLConnection.getFileNameMap(). The signature does not change. The default for an unknown name or a null name is stillapplication/octet-stream(a null name threw an exception before). Thecom.sun.activation:javax.activationdependency is removed, and nothing else in the library usesjavax.activation. The library now has no Java EE or Jakarta EE API dependency.Behavior difference: the JDK table knows more types than the default table of javax.activation, so some files get a more exact type. The results for common extensions:
.png.PNG.jpg,.jpeg.gif.txt.html.pdf.zip.webp.json.svg.mp4.csv.heic"Before, JDK 8" is lower than "Before, JDK 11" because on JDK 8 the
javax.activationclasses of the JDK itself take precedence over the 1.2.0 jar. No type became less exact.Fixes #50
Tests on JUnit 6
The 4 test classes move from JUnit 4 to JUnit 6 (
org.junit.jupiter.api,@BeforeEach,assertThrows).CdnPathBuilderTestusesMockitoExtensionwith@Mock.FileUploaderTestkeepsmock(), because the strict stubs ofMockitoExtensionreject its second, unstubbedexecuteQuerycall.JUnit 6 needs Java 17 to run. The published library still targets Java 7:
compileJavauses--release 7. JDK 17 is the newest LTS JDK that supports release 7 (JDK 20 removed it), and it gives a warning that-Xlint:-optionshides.compileTestJavauses--release 17../gradlew buildworks when Gradle runs on JDK 17 or later.-PtestJavaVersion=21runs them on JDK 21.Client.classin the built jar has class file major version 51 (Java 7), as before. The Gradle module metadata hasorg.gradle.jvm.version: 7. The jar works on JDK 8:Client.demoClient()andRequestHelper.getMimeType("olympia.jpg")run with no error.CI changes:
./gradlew build -PtestJavaVersion=<matrix JDK>.build.ymlusespull_request_target, so the run for this PR uses the workflow ofmaster(JDK 8 and 11), not the new matrix. On this PR, that run fails at the Checkout step before the build:actions/checkoutrefuses to check out fork pull request code from apull_request_targetworkflow. This happens for any PR from a fork, and this PR does not change it. Onmaster(JDK 8 and 11), the tests would also fail, because JUnit 6 needs Java 17. The new matrix applies after the merge.Overlap with draft #73: #73 also moves the tests to JUnit 6 and Mockito 5. But #73 also moves the library itself to Java 21, while this PR keeps the Java 7 target. If #73 merges first, this PR needs a rebase on the test and build files.
Tests
./gradlew buildpasses with Gradle on Temurin JDK 17 (17.0.21), tests on JDK 17../gradlew build -PtestJavaVersion=21passes with Gradle on Corretto JDK 21 (21.0.12). The compile used the JDK 17 toolchain that the foojay plugin downloaded, and the tests ran on JDK 21../gradlew buildalso passed on Temurin JDK 8 (1.8.0_504) and JDK 11 (11.0.32.1).FileTest(1),RequestHelperTest(3),CdnPathBuilderTest(5),FileUploaderTest(2).RequestHelperTestcreates aClientand thus covers the Jackson change. The newRequestHelperTest.test_getMimeTypecovers.png,.jpg,.txt, an unknown extension, no extension and null.NoSuchFieldErrorabove. The jar from this branch createsClient.demoClient()with no error.IllegalAccessErrorof Provide support for Jakarta EE #50 locally (3.5.3 with jakarta.activation-api 2.1.1, jakarta.activation 2.0.1 or angus-activation 2.0.1 on JDK 11 did not fail). The change removes the cause: the library no longer loads anyjavax.activationclass.