Skip to content

Fix #16295: JSON SPI loading without optional dependencies#16385

Open
larrychen1024 wants to merge 1 commit into
apache:3.3from
larrychen1024:fix/json-utils-missing-gson
Open

Fix #16295: JSON SPI loading without optional dependencies#16385
larrychen1024 wants to merge 1 commit into
apache:3.3from
larrychen1024:fix/json-utils-missing-gson

Conversation

@larrychen1024

@larrychen1024 larrychen1024 commented Jul 16, 2026

Copy link
Copy Markdown

What is the purpose of the change?

Fixes #16295.

On JDK 25, ServiceLoader.Iterator#hasNext() may resolve a JSON provider's constructor and its referenced types. If an optional JSON implementation such as Gson is not present, this can throw NoClassDefFoundError before Dubbo can continue to the default fastjson2 implementation.

Brief changelog

  • Keep ServiceLoader#hasNext(), provider construction, and support checks inside the guarded iteration.
  • Skip provider loading failures caused by ServiceConfigurationError, LinkageError, or provider runtime exceptions.
  • Avoid catching fatal JVM errors through a blanket Throwable catch.
  • Add a regression test that hides all Gson classes while retaining the Gson service provider entry, and verifies that fastjson2 is still discovered.

Verifying this change

  • Reproduced the original NoClassDefFoundError: com/google/gson/JsonSyntaxException locally on Temurin JDK 25.0.3 with the Dubbo 3.3.6 loading logic and Gson removed from the runtime classpath.
  • Verified the fixed runtime selects FastJson2Impl without Gson on JDK 25.0.3 and JDK 26.0.1.
  • JsonUtilsTest: 6 tests passed on JDK 25.0.3.
  • The new missing-Gson regression test passed on JDK 25.0.3 and JDK 26.0.1.
  • Spotless formatting check passed.

@larrychen1024 larrychen1024 changed the title Fix JSON SPI loading without optional dependencies Fix #16295:JSON SPI loading without optional dependencies Jul 16, 2026
@larrychen1024 larrychen1024 changed the title Fix #16295:JSON SPI loading without optional dependencies Fix #16295: JSON SPI loading without optional dependencies Jul 16, 2026
@codecov-commenter

codecov-commenter commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.87%. Comparing base (d0bf5c3) to head (316d0f9).

Additional details and impacted files
@@            Coverage Diff            @@
##                3.3   #16385   +/-   ##
=========================================
  Coverage     60.86%   60.87%           
- Complexity    11763    11773   +10     
=========================================
  Files          1953     1953           
  Lines         89262    89262           
  Branches      13471    13471           
=========================================
+ Hits          54331    54338    +7     
- Misses        29329    29336    +7     
+ Partials       5602     5588   -14     
Flag Coverage Δ
integration-tests-java21 32.16% <100.00%> (+0.05%) ⬆️
integration-tests-java8 32.30% <100.00%> (+0.14%) ⬆️
samples-tests-java21 32.19% <100.00%> (+0.04%) ⬆️
samples-tests-java8 29.85% <100.00%> (+0.06%) ⬆️
unit-tests-java11 59.07% <100.00%> (-0.05%) ⬇️
unit-tests-java17 58.58% <100.00%> (-0.02%) ⬇️
unit-tests-java21 58.55% <100.00%> (-0.06%) ⬇️
unit-tests-java25 58.53% <100.00%> (-0.01%) ⬇️
unit-tests-java8 59.09% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] When running a Dubbo 3.3.6 application on JDK 25, application startup fails with NoClassDefFoundError: com/google/gson/JsonSyntaxException.

2 participants