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

IndexOutOfBoundsException in UseEnumCollections #434

Closed nkavian closed 3 weeks ago

nkavian commented 2 years ago

It think it's this something like this signature from my class. There is no other usage of a collection or enum other than this inside the class.

enum AnEnum { A, B, C }
public void someMethod(final Collection<AnEnum> collection) {

Stack trace below.

Exception analyzing com.example.MyClass using detector com.mebigfatguy.fbcontrib.detect.UseEnumCollections
java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
    at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
    at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
    at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
    at java.base/java.util.Objects.checkIndex(Objects.java:359)
    at java.base/java.util.ArrayList.get(ArrayList.java:427)
    at com.mebigfatguy.fbcontrib.utils.TernaryPatcher.post(TernaryPatcher.java:87)
    at com.mebigfatguy.fbcontrib.detect.UseEnumCollections.sawOpcode(UseEnumCollections.java:207)
    at edu.umd.cs.findbugs.visitclass.DismantleBytecode.visit(DismantleBytecode.java:878)
    at edu.umd.cs.findbugs.visitclass.BetterVisitor.visitCode(BetterVisitor.java:218)
    at edu.umd.cs.findbugs.visitclass.PreorderVisitor.visitCode(PreorderVisitor.java:243)
    at com.mebigfatguy.fbcontrib.detect.UseEnumCollections.visitCode(UseEnumCollections.java:113)
    at org.apache.bcel.classfile.Code.accept(Code.java:131)
    at edu.umd.cs.findbugs.visitclass.PreorderVisitor.doVisitMethod(PreorderVisitor.java:315)
    at edu.umd.cs.findbugs.visitclass.PreorderVisitor.visitJavaClass(PreorderVisitor.java:397)
    at org.apache.bcel.classfile.JavaClass.accept(JavaClass.java:213)
    at edu.umd.cs.findbugs.BytecodeScanningDetector.visitClassContext(BytecodeScanningDetector.java:38)
    at com.mebigfatguy.fbcontrib.detect.UseEnumCollections.visitClassContext(UseEnumCollections.java:88)
    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:264)
    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 de.tobject.findbugs.builder.FindBugsWorker.runFindBugs(FindBugsWorker.java:314)
    at de.tobject.findbugs.builder.FindBugsWorker.work(FindBugsWorker.java:220)
    at de.tobject.findbugs.actions.FindBugsAction$StartedFromViewJob.runWithProgress(FindBugsAction.java:275)
    at de.tobject.findbugs.FindBugsJob.run(FindBugsJob.java:142)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
mebigfatguy commented 1 year ago

there had to have been some code using ? in this that tripped the error? Can you give a sample?

nkavian commented 1 year ago

It's been so long, I don't know how to reproduce it. Feel free to close the ticket.

mebigfatguy commented 3 weeks ago

can't reproduce