Icesource opened a new issue, #16574:
URL: https://github.com/apache/dubbo/issues/16574

   ### Pre-check
   
   - [x] All content is in English.
   
   ### Search before asking
   
   I searched existing issues and open PRs. Issues 
https://github.com/apache/dubbo/issues/12362 and 
https://github.com/apache/dubbo/issues/14542 report missing generic types 
during this scan. This report supplies regression cases for the resulting 
incomplete allow list, including a missing raw field type, and proposes 
isolating those failures so healthy DTOs remain discoverable.
   
   ### Apache Dubbo Component
   
   Java SDK (apache/dubbo)
   
   ### Dubbo Version
   
   - Reproduced on the `3.3` branch at 
`2d9730c6ab4358d94c6e3594fdd2dca0009fe912` (`3.3.7-SNAPSHOT`).
   - The scanner and `ProtocolSecurityWrapper` sources in the `dubbo-3.3.6` tag 
have the same behavior; the regression tests below were run against the pinned 
`3.3` commit.
   - OpenJDK 17.0.20.1, macOS.
   
   ### Steps to reproduce this issue
   
   Compile a service and its DTOs with an optional dependency present, then run 
with that dependency absent from the service's class loader. The smallest model 
is:
   
   ```java
   public interface FieldService {
       Healthy read(MissingField value);
   }
   
   public class MissingField {
       public OptionalDependency optional;
   }
   
   public class Healthy implements java.io.Serializable {
       public Nested value;
   }
   
   public class Nested implements java.io.Serializable {}
   ```
   
   `OptionalDependency` exists at compile time but is deliberately hidden at 
runtime. The service and both parameter/return classes can still be loaded. No 
instance of `MissingField` needs to be deserialized for this failure to occur.
   
   1. Enable automatic serialization trust, `trustSerializeClassLevel = 
Integer.MAX_VALUE`, and `serializeCheckStatus = STRICT` on a fresh 
framework/application.
   2. Call 
`SerializeSecurityConfigurator.registerInterface(FieldService.class)` with the 
service loaded by the incomplete class loader.
   3. The scanner visits `MissingField` before the method's `Healthy` return 
type. `MissingField.getDeclaredFields()` throws `NoClassDefFoundError`, 
aborting the registration scan before `Healthy` or `Nested` is visited.
   4. `DefaultSerializeClassChecker` still rejects `Healthy` as absent from the 
allow list. Calling `registerInterface` again does not complete the scan: the 
interface has already entered `markedTypeCache`.
   
   The regression test uses a child-first loader for the fixture classes and 
refuses only `OptionalDependency`; it exercises actual JDK reflection failures, 
rather than mocking reflection. Its eight cases cover:
   
   - A missing raw field type.
   - A missing transient field type (filtering transient fields happens after 
`getDeclaredFields()`).
   - A missing generic method parameter type, with a healthy return type on the 
same method.
   - A missing generic field type, with a healthy sibling field.
   - A missing generic interface argument, with healthy DTO fields.
   - A missing generic superclass argument, with healthy DTO fields.
   - A missing type-variable bound.
   - A missing generic method return type, with another healthy service method.
   
   The test and fixture files, along with commands for running them 
before/after the fix, will be linked from the associated PR.
   
   ### Actual behavior
   
   The raw-field case fails with:
   
   ```text
   java.lang.NoClassDefFoundError: 
com/serialization/MissingTypeFixtures$OptionalDependency
       at java.lang.Class.getDeclaredFields0(Native Method)
       at java.lang.Class.privateGetDeclaredFields(...)
       at java.lang.Class.getDeclaredFields(...)
       at 
org.apache.dubbo.common.utils.SerializeSecurityConfigurator.checkClass(...)
       at 
org.apache.dubbo.common.utils.SerializeSecurityConfigurator.registerInterface(...)
   Caused by: java.lang.ClassNotFoundException: 
com.serialization.MissingTypeFixtures$OptionalDependency
   ```
   
   The generic cases fail with `TypeNotPresentException` (for example, at 
`Field.getGenericType()` or `Class.getGenericInterfaces()`).
   
   `ProtocolSecurityWrapper` catches the failure around the whole registration 
scan, logs it, and proceeds with export/refer. This can leave an apparently 
registered service with an incomplete allow list. Already trusted types, such 
as `String`, need not fail; healthy DTOs that were never reached can be 
rejected by STRICT checking. The affected set depends on traversal order and 
any existing explicit/package allow rules.
   
   ### What you expected to happen
   
   Log the unresolved type/metadata, skip the part that cannot be inspected, 
and continue independent fields, types, and service methods. Continue to reject 
unrelated/unknown classes under STRICT; do not change the configured trust 
level or fall back to WARN.
   
   This does **not** ask Dubbo to make an actually missing dependency usable. 
In particular, if `getDeclaredFields()` fails before returning its array, 
reflection cannot enumerate the other fields of that class; callers should 
still be able to scan other classes. A missing raw service-method signature 
type that prevents `getMethods()` itself from returning is also outside this 
fix.
   
   ### Anything else
   
   Related allow-list discovery issue: 
https://github.com/apache/dubbo/issues/16569 and its fix 
https://github.com/apache/dubbo/pull/16570. That pair addresses array component 
traversal; this report addresses failure isolation for missing dependencies and 
does not depend on the array fix.
   
   Validation on JDK 17:
   
   - Without the production fix: all 8 new regression cases fail with the 
expected missing-type errors.
   - With the fix: `mvn -B -ntp -pl dubbo-common -am clean test` succeeds: 
1,186 tests, 0 failures, 0 errors, 10 skipped, including Spotless checks.
   - Each new case verifies healthy and nested DTO discovery plus continued 
rejection of an unrelated class under STRICT.
   
   ### Do you have a (mini) reproduction demo?
   
   - [x] Yes: isolated-classloader regression tests accompanying the PR.
   
   ### Are you willing to submit a pull request to fix on your own?
   
   - [x] Yes.
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to