Fix Sanitizer crashing on JDK-internal fields when given JDK objects
findItems() unconditionally read every field's value via reflection
just to check whether it was annotated or embeddable, even for fields
neither use needed. This forces access to JDK-internal fields (e.g.
java.util.ArrayList#serialVersionUID) when a JDK collection/object is
passed directly as the sanitize() target, which the module system
blocks without --add-opens and throws InaccessibleObjectException for.

Now the annotated/embeddable check happens first, using only field
metadata, and the value is read only when actually needed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 6a4d9c2 commit 8df370af833c2cc678348fcd1dec8dcc0ad247fe
@aljunggren aljunggren authored on 21 Jun
Showing 2 changed files
View
src/main/java/io/ljunggren/sanitizer/Sanitizer.java
View
src/test/java/io/ljunggren/sanitizer/SanitizerExtraTest.java