Skip to content

[java] AssertionError when outer class is parsed before inner class with conflicting visibility #6932

Closed

Description

@Scrates1

Affected version

  • PMD 7.24.0
  • Current main / 7.27.0-SNAPSHOT at 8c0a935

Description

When PMD loads an Android dependency processed by R8, ClassStub can merge contradictory visibility flags for the same nested class into public private. A later symbol-table accessibility check treats this combination as unreachable and throws an AssertionError, aborting analysis of the source file.

This is related to #5283 and #5310, but exercises the opposite lazy-loading order. The fix in #5310 removes public when a non-public InnerClasses entry is merged after the class header. It does not handle the outer class being parsed first.

In the failing order, calls for one ClassStub are equivalent to:

inner.setModifiers(Opcodes.ACC_PRIVATE, false);                  // outer InnerClasses entry
inner.setModifiers(Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, true); // inner ClassInfo
inner.setModifiers(Opcodes.ACC_PUBLIC, false);                   // inner self-entry

The result is 3 (public private) instead of 2 (private).

Minimal bytecode shape

The issue can be reproduced without the original dependency by generating two classes with ASM:

  • Outer.class: public class; its InnerClasses entry declares Outer$Inner private.
  • Outer$Inner.class: public class header; its own InnerClasses entry declares itself public.
  • Resolve/parse Outer before Outer$Inner.

This models the inconsistent but parseable metadata observed in an R8-processed Android AAR. No source-level Java declaration can express the contradictory metadata.

Exception

java.lang.AssertionError: This should be unreachable: private field of an interface? ... modifiers: public private static
    at net.sourceforge.pmd.util.AssertionUtil.shouldNotReachHere(AssertionUtil.java:243)
    at net.sourceforge.pmd.lang.java.symbols.table.internal.JavaResolvers.isAccessible(JavaResolvers.java:479)
    at net.sourceforge.pmd.lang.java.symbols.table.internal.JavaResolvers.processDeclarations(JavaResolvers.java:432)
    at net.sourceforge.pmd.lang.java.symbols.table.internal.JavaResolvers.walkSelf(JavaResolvers.java:409)

Expected behavior

Merging class-header and InnerClasses access flags should be independent of lazy class parsing order and should never retain more than one visibility flag. Consistent with #5310, the non-public InnerClasses visibility should take precedence over ACC_PUBLIC.

pmd.error_recovery=true limits the impact by reporting a processing error and skipping the affected source file, but it is not a complete fix because all PMD rules are then skipped for that file.

Activity

  1. added
    a:bug
    on Aug 14, 2026
  2. added this to the 7.27.0 milestone on Aug 14, 2026
  3. added a commit that references this issue on Aug 14, 2026
    54c793f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions