Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception Can't get stack offset 0 from [] #2019

Closed
pbludov opened this issue Apr 18, 2022 · 1 comment
Closed

Exception Can't get stack offset 0 from [] #2019

pbludov opened this issue Apr 18, 2022 · 1 comment
Labels

Comments

@pbludov
Copy link

@pbludov pbludov commented Apr 18, 2022

Code

public class IssueXXX {

    static class ATNSimulator {
        public int adaptivePredict() {
            return 0;
        }
    }

    static class ParserATNSimulator extends ATNSimulator {
    }

    static class Recognizer<ATNInterpreter extends ATNSimulator> {
        public ATNInterpreter getInterpreter() {
            return null;
        }
    }

    static class BaseParser extends Recognizer<ParserATNSimulator> {
    }

    public static class Parser extends BaseParser {

        public void text() {
            int _alt = 1;
            do {
                switch (_alt) {
                    case 1:
                        if (_alt == 1) {
                            continue;
                        }
                        break;
                    default:
                        throw new RuntimeException();
                }
                _alt = getInterpreter().adaptivePredict();
            } while (_alt != 2);
        }

    }}

Bytecode

  // access flags 0x1
  public text()V
   L0
    LINENUMBER 29 L0
    ICONST_1
    ISTORE 1
   L1
    LINENUMBER 31 L1
   FRAME APPEND [I]
    ILOAD 1
    LOOKUPSWITCH
      1: L2
      default: L3
   L2
    LINENUMBER 33 L2
   FRAME SAME
    ILOAD 1
    ICONST_1
    IF_ICMPNE L4
   L5
    LINENUMBER 34 L5
    GOTO L6
   L3
    LINENUMBER 38 L3
   FRAME SAME
    NEW java/lang/RuntimeException
    DUP
    INVOKESPECIAL java/lang/RuntimeException.<init> ()V
    ATHROW
   L4
    LINENUMBER 40 L4
   FRAME SAME
    ALOAD 0
    INVOKEVIRTUAL ghIssues/Issue2017$Parser.getInterpreter ()LghIssues/Issue2017$ATNSimulator;
    CHECKCAST ghIssues/Issue2017$ParserATNSimulator
    INVOKEVIRTUAL ghIssues/Issue2017$ParserATNSimulator.adaptivePredict ()I
    ISTORE 1
   L6
    LINENUMBER 41 L6
   FRAME SAME
    ILOAD 1
    ICONST_2
    IF_ICMPNE L1
   L7
    LINENUMBER 42 L7
    RETURN
   L8
    LOCALVARIABLE this LghIssues/Issue2017$Parser; L0 L8 0
    LOCALVARIABLE _alt I L1 L8 1
    MAXSTACK = 2
    MAXLOCALS = 2

Exception

The following errors occurred during analysis:
  Can't get stack offset 0 from [] @ 40 in ghIssues.IssueXXXX$Parser.text : ()V
    java.lang.IllegalArgumentException: 0 is not a value stack offset
      At edu.umd.cs.findbugs.OpcodeStack.getStackItem(OpcodeStack.java:3156)
      At edu.umd.cs.findbugs.detect.FindReturnRef.afterOpcode(FindReturnRef.java:300)
      At edu.umd.cs.findbugs.visitclass.DismantleBytecode.visit(DismantleBytecode.java:880)
      At edu.umd.cs.findbugs.detect.FindReturnRef.visit(FindReturnRef.java:119)
      At edu.umd.cs.findbugs.visitclass.BetterVisitor.visitCode(BetterVisitor.java:218)
      At edu.umd.cs.findbugs.visitclass.PreorderVisitor.visitCode(PreorderVisitor.java:243)
      At edu.umd.cs.findbugs.bcel.OpcodeStackDetector.visitCode(OpcodeStackDetector.java:65)
      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 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 edu.umd.cs.findbugs.test.AnalysisRunner.run(AnalysisRunner.java:115)
@pbludov
Copy link
Author

@pbludov pbludov commented Apr 18, 2022

Original file generated by ANTLR for reference:
https://gist.github.com/pbludov/3bac5ebbdce6c2ab1eab083a87d9adf6#file-javadocparser-java-L16979

KengoTODA added a commit that referenced this issue Apr 19, 2022
@KengoTODA KengoTODA added the bug label Apr 19, 2022
KengoTODA added a commit that referenced this issue Apr 19, 2022
IllegalArgumentException is thrown when CHECKCAST bytecode is used
even when the operand stack is TOP.

close #2019
KengoTODA added a commit that referenced this issue Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants