Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-2609

Resolving supertype of anonymous class leads to IllegalStateException

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.0.1
    • Fix Version/s: 5.3
    • Component/s: Semantic
    • Labels:
      None

      Description

      When method has exceptional yield where exception type is anonymous class and this yield is used in another method, we will attempt to resolve this anonymous exception type from bytecode, which fails with IllegalStateException.

      This can be reproduced when following snippet is analyzed with the compiled anonymous exception available in the classpath

      class TestSupertypeResolution {
        private void test() throws Exception {
          throw new Exception() {};
        }
      
        void call() throws Exception {
          test();
        }
      }
      

      Following is the stacktrace

      Caused by: java.lang.IllegalStateException
      	at org.sonar.java.resolve.BytecodeVisitor.visitOuterClass(BytecodeVisitor.java:128)
      	at org.objectweb.asm.ClassReader.accept(ClassReader.java:648)
      	at org.objectweb.asm.ClassReader.accept(ClassReader.java:521)
      	at org.sonar.java.resolve.BytecodeCompleter.complete(BytecodeCompleter.java:80)
      	at org.sonar.java.resolve.JavaSymbol.complete(JavaSymbol.java:110)
      	at org.sonar.java.resolve.JavaSymbol$TypeJavaSymbol.getSuperclass(JavaSymbol.java:356)
      	at org.sonar.java.resolve.JavaSymbol$TypeJavaSymbol.superClass(JavaSymbol.java:450)
      	at org.sonar.java.resolve.JavaSymbol$TypeJavaSymbol.superTypes(JavaSymbol.java:417)
      	at org.sonar.java.resolve.ClassJavaType.superTypeContains(ClassJavaType.java:85)
      	at org.sonar.java.resolve.ClassJavaType.isSubtypeOf(ClassJavaType.java:57)
      	at org.sonar.java.se.ProgramState.exitingOnRuntimeException(ProgramState.java:537)
      	at org.sonar.java.se.checks.UnclosedResourcesCheck.checkEndOfExecutionPath(UnclosedResourcesCheck.java:150)
      	at org.sonar.java.se.CheckerDispatcher.executeCheckEndOfExecutionPath(CheckerDispatcher.java:141)
      	at org.sonar.java.se.ExplodedGraphWalker.lambda$handleEndOfExecutionPath$0(ExplodedGraphWalker.java:314)
      	at java.lang.Iterable.forEach(Iterable.java:75)
      	at org.sonar.java.se.ExplodedGraphWalker.handleEndOfExecutionPath(ExplodedGraphWalker.java:312)
      	at org.sonar.java.se.ExplodedGraphWalker.execute(ExplodedGraphWalker.java:266)
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                michael.gumowski Michael Gumowski
                Reporter:
                tibor.blenessy Tibor Blenessy
              • Votes:
                2 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: