Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8355065

ConcurrentModificationException in RichDiagnosticFormatter

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P2 P2
    • None
    • None
    • tools

      In the following example, javac crashes with a ConcurrentModificationException in RichDiagnosticFormatter while reporting interleaved raw.class.use and unknown.enum.constant diagnostics.

      The repro involves deleting an enum referenced from an annotation from the classpath to force the unknown.enum.constant diagnostic to happen, which wouldn't occur if the classpath was complete, but javac shouldn't crash when reporting these diagnostics.

      === M.java
      import java.lang.annotation.ElementType;
      import java.lang.annotation.Retention;
      import java.lang.annotation.RetentionPolicy;
      import java.lang.annotation.Target;

      enum Bar {
        BAZ
      }

      @Retention(RetentionPolicy.RUNTIME)
      @interface Foo {
        Bar value();
      }

      @Retention(RetentionPolicy.RUNTIME)
      @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
      @Foo(Bar.BAZ)
      @interface A {}

      public interface M<K, V> {
        @A
        V put(K k, V v);
      }
      === T.java
      class T {
        protected M m;

        public void getUniqueID() {
          m.put(null, 0);
        }
      }
      ===

      $ javac -fullversion
      javac full version "25-ea+19-2255"

      $ javac M.java
      $ rm Bar.class
      $ javac -Xlint:unchecked,rawtypes T.java
      ...
      T.java:2: warning: [rawtypes] found raw type: M
        protected M m;
                  ^
        missing type arguments for generic class M<K,V>
        where K,V are type-variables:
          K extends Object declared in interface M
          V extends Object declared in interface M
      warning: unknown enum constant Bar.BAZ
        reason: class file for Bar not found
      2 warnings
      An exception has occurred in the compiler (24). Please file a bug: go/javac-bug
      Include the sponge link in your report.
      java.util.ConcurrentModificationException
              at java.base/java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:1024)
              at java.base/java.util.LinkedHashMap$LinkedKeyIterator.next(LinkedHashMap.java:1047)
              at jdk.compiler/com.sun.tools.javac.util.RichDiagnosticFormatter.indexOf(RichDiagnosticFormatter.java:230)
              at jdk.compiler/com.sun.tools.javac.util.RichDiagnosticFormatter$1.visitTypeVar(RichDiagnosticFormatter.java:560)
              at jdk.compiler/com.sun.tools.javac.util.RichDiagnosticFormatter$1.visitTypeVar(RichDiagnosticFormatter.java:463)
              at jdk.compiler/com.sun.tools.javac.code.Type$TypeVar.accept(Type.java:1709)
              at jdk.compiler/com.sun.tools.javac.code.Types$UnaryVisitor.visit(Types.java:5016)
              at jdk.compiler/com.sun.tools.javac.util.RichDiagnosticFormatter$1.visitMethodType(RichDiagnosticFormatter.java:481)
              at jdk.compiler/com.sun.tools.javac.util.RichDiagnosticFormatter$1.visitMethodType(RichDiagnosticFormatter.java:463)
              at jdk.compiler/com.sun.tools.javac.code.Type$MethodType.accept(Type.java:1499)
              at jdk.compiler/com.sun.tools.javac.code.Types$UnaryVisitor.visit(Types.java:5016)
              at jdk.compiler/com.sun.tools.javac.util.RichDiagnosticFormatter$2.visitMethodSymbol(RichDiagnosticFormatter.java:635)
              at jdk.compiler/com.sun.tools.javac.util.RichDiagnosticFormatter$2.visitMethodSymbol(RichDiagnosticFormatter.java:614)
              at jdk.compiler/com.sun.tools.javac.code.Symbol$MethodSymbol.accept(Symbol.java:2314)
              at jdk.compiler/com.sun.tools.javac.code.Types$DefaultSymbolVisitor.visit(Types.java:4963)
              at jdk.compiler/com.sun.tools.javac.util.RichDiagnosticFormatter.preprocessSymbol(RichDiagnosticFormatter.java:610)
              at jdk.compiler/com.sun.tools.javac.util.RichDiagnosticFormatter.preprocessArgument(RichDiagnosticFormatter.java:191)
              at jdk.compiler/com.sun.tools.javac.util.RichDiagnosticFormatter.preprocessDiagnostic(RichDiagnosticFormatter.java:168)
              at jdk.compiler/com.sun.tools.javac.util.RichDiagnosticFormatter.format(RichDiagnosticFormatter.java:117)
              at jdk.compiler/com.sun.tools.javac.util.RichDiagnosticFormatter.format(RichDiagnosticFormatter.java:72)
              at jdk.compiler/com.sun.tools.javac.util.Log.writeDiagnostic(Log.java:747)
              at jdk.compiler/com.sun.tools.javac.util.Log$DefaultDiagnosticHandler.report(Log.java:710)
              at jdk.compiler/com.sun.tools.javac.util.Log.report(Log.java:675)
              at jdk.compiler/com.sun.tools.javac.util.AbstractLog.mandatoryWarning(AbstractLog.java:217)
              at jdk.compiler/com.sun.tools.javac.util.MandatoryWarningHandler.logMandatoryWarning(MandatoryWarningHandler.java:262)
              at jdk.compiler/com.sun.tools.javac.util.MandatoryWarningHandler.report(MandatoryWarningHandler.java:138)
              at jdk.compiler/com.sun.tools.javac.comp.Check.warnUnchecked(Check.java:306)

            cushon Liam Miller-Cushon
            cushon Liam Miller-Cushon
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: