mebigfatguy / fb-contrib

a FindBugs/SpotBugs plugin for doing static code analysis for java code bases
http://fb-contrib.sf.net
GNU Lesser General Public License v2.1
157 stars 45 forks source link

`IncorrectInternalClassUse` throws a `ClassFormatException` after upgrading to Spotbugs 6.0.3 #456

Closed donalmurtagh closed 11 months ago

donalmurtagh commented 11 months ago

I upgraded the Spotbugs Gradle plugin from 6.0.2 to 6.0.3. After the upgrade I ran the checks, and I now get a lot of these exceptions (one for every class analysed, I think)

The following errors occurred during analysis:
  Exception analyzing com.example.MyClass using detector com.mebigfatguy.fbcontrib.detect.IncorrectInternalClassUse
    org.apache.bcel.classfile.ClassFormatException: Invalid constant pool reference using index: 0. Constant pool size is: 44
      At org.apache.bcel.classfile.ConstantPool.getConstant(ConstantPool.java:305)
      At org.apache.bcel.classfile.ConstantPool.getConstant(ConstantPool.java:257)
      At com.mebigfatguy.fbcontrib.detect.IncorrectInternalClassUse.visitClassContext(IncorrectInternalClassUse.java:85)
      At edu.umd.cs.findbugs.DetectorToDetector2Adapter.visitClass(DetectorToDetector2Adapter.java:76)
      At edu.umd.cs.findbugs.FindBugs2.lambda$analyzeApplication$1(FindBugs2.java:1108)
      At java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
      At edu.umd.cs.findbugs.CurrentThreadExecutorService.execute(CurrentThreadExecutorService.java:86)
      At java.base/java.util.concurrent.AbstractExecutorService.invokeAll(AbstractExecutorService.java:247)
      At edu.umd.cs.findbugs.FindBugs2.analyzeApplication(FindBugs2.java:1118)
      At edu.umd.cs.findbugs.FindBugs2.execute(FindBugs2.java:309)
      At edu.umd.cs.findbugs.FindBugs.runMain(FindBugs.java:395)
      At edu.umd.cs.findbugs.FindBugs2.main(FindBugs2.java:1231)

I'm using v7.6.3 of sb-contrib.

mebigfatguy commented 11 months ago

is it possible to get the .classfile for the problematic class? What version of java was the target class compiled in?

donalmurtagh commented 11 months ago

is it possible to get the .classfile for the problematic class? What version of java was the target class compiled in?

@mebigfatguy When you say "problematic class", do you mean the class being analyzed, i.e. com.example.MyClass in the example above? My app uses JDK21, so that's what all of the analyzed classes were compiled with.

mebigfatguy commented 11 months ago

yes com.example.MyClass, probably related to jdk21

donalmurtagh commented 11 months ago

@mebigfatguy I added the following trivial class to my project

package com.example;

public class MyClass {
}

I ran Spotbugs and confirmed that the error occurs for this class (it seems to occur for every analysed class).

  Exception analyzing com.example.MyClass using detector com.mebigfatguy.fbcontrib.detect.IncorrectInternalClassUse
    org.apache.bcel.classfile.ClassFormatException: Invalid constant pool reference using index: 0. Constant pool size is: 16
      At org.apache.bcel.classfile.ConstantPool.getConstant(ConstantPool.java:305)
      At org.apache.bcel.classfile.ConstantPool.getConstant(ConstantPool.java:257)
      At com.mebigfatguy.fbcontrib.detect.IncorrectInternalClassUse.visitClassContext(IncorrectInternalClassUse.java:85)
      At edu.umd.cs.findbugs.DetectorToDetector2Adapter.visitClass(DetectorToDetector2Adapter.java:76)

I've attached MyClass.class file to this comment. I had to add it as a .zip archive because GitHub doesn't allow .class file attachments.

MyClass.class.zip

mebigfatguy commented 11 months ago

targetted for 7.6.4