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

Error printed in spotbugs output #11453

Closed
romani opened this issue Mar 22, 2022 · 10 comments
Closed

Error printed in spotbugs output #11453

romani opened this issue Mar 22, 2022 · 10 comments
Assignees
Labels

Comments

@romani
Copy link
Member

romani commented Mar 22, 2022

build is not failed.

$ mvn --version
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Maven home: /opt/maven/apache-maven-3.8.4
Java version: 11.0.14.1, vendor: Amazon.com Inc., runtime: /opt/jvm/amazon-corretto-11.0.14.10.1-linux-x64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-210-generic", arch: "amd64", family: "unix"

$ mvn verify
....
[INFO] 
[INFO] --- spotbugs-maven-plugin:4.5.3.0:spotbugs (spotbugs) @ checkstyle ---
[INFO] Fork Value is true
     [java] The following errors occurred during analysis:
     [java]   Can't get stack offset 0 from [] @ 219 in com.puppycrawl.tools.checkstyle.grammar.javadoc.JavadocParser.text : ()Lcom.puppycrawl.tools.checkstyle.grammar.javadoc.JavadocParser$TextContext;
     [java]     java.lang.IllegalArgumentException: 0 is not a value stack offset
     [java]       At edu.umd.cs.findbugs.OpcodeStack.getStackItem(OpcodeStack.java:3156)
     [java]       At edu.umd.cs.findbugs.detect.FindReturnRef.afterOpcode(FindReturnRef.java:300)
     [java]       At edu.umd.cs.findbugs.visitclass.DismantleBytecode.visit(DismantleBytecode.java:880)
     [java]       At edu.umd.cs.findbugs.detect.FindReturnRef.visit(FindReturnRef.java:119)
     [java]       At edu.umd.cs.findbugs.visitclass.BetterVisitor.visitCode(BetterVisitor.java:218)
     [java]       At edu.umd.cs.findbugs.visitclass.PreorderVisitor.visitCode(PreorderVisitor.java:243)
     [java]       At edu.umd.cs.findbugs.bcel.OpcodeStackDetector.visitCode(OpcodeStackDetector.java:65)
     [java]       At org.apache.bcel.classfile.Code.accept(Code.java:131)
     [java]       At edu.umd.cs.findbugs.visitclass.PreorderVisitor.doVisitMethod(PreorderVisitor.java:315)
     [java]       At edu.umd.cs.findbugs.visitclass.PreorderVisitor.visitJavaClass(PreorderVisitor.java:397)
     [java]       At org.apache.bcel.classfile.JavaClass.accept(JavaClass.java:213)
     [java]       At edu.umd.cs.findbugs.BytecodeScanningDetector.visitClassContext(BytecodeScanningDetector.java:38)
     [java]       At edu.umd.cs.findbugs.DetectorToDetector2Adapter.visitClass(DetectorToDetector2Adapter.java:76)
     [java]       At edu.umd.cs.findbugs.FindBugs2.lambda$analyzeApplication$1(FindBugs2.java:1108)
     [java]       At java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
     [java]       At edu.umd.cs.findbugs.CurrentThreadExecutorService.execute(CurrentThreadExecutorService.java:86)
     [java]       At java.base/java.util.concurrent.AbstractExecutorService.invokeAll(AbstractExecutorService.java:242)
     [java]       At edu.umd.cs.findbugs.FindBugs2.analyzeApplication(FindBugs2.java:1118)
     [java]       At edu.umd.cs.findbugs.FindBugs2.execute(FindBugs2.java:309)
     [java]       At edu.umd.cs.findbugs.FindBugs.runMain(FindBugs.java:395)
     [java]       At edu.umd.cs.findbugs.FindBugs2.main(FindBugs2.java:1231)
[INFO] Done SpotBugs Analysis....

@pbludov
Copy link
Member

pbludov commented Mar 22, 2022

The problematic code is

	public final TextContext text() throws RecognitionException {
		TextContext _localctx = new TextContext(_ctx, getState());
		enterRule(_localctx, 148, RULE_text);
		int _la;
		try {
			int _alt;
			enterOuterAlt(_localctx, 1);
			{
			setState(2064); 
			_errHandler.sync(this);
			_alt = 1;
			do {
				switch (_alt) {
				case 1:
					{
					{
					setState(2062);
					_la = _input.LA(1);
					if ( !(_la==WS || _la==CHAR) ) {
					_errHandler.recoverInline(this);
					}
					else {
						if ( _input.LA(1)==Token.EOF ) matchedEOF = true;
						_errHandler.reportMatch(this);
						consume();
					}

					  _la = _input.LA(1);
					  if ((_la != WS) && (_la != CHAR)) return _localctx;
					  else if (_alt == 1) continue;
					 
					}
					}
					break;
				default:
					throw new NoViableAltException(this);
				}
				setState(2066); 
				_errHandler.sync(this);
				_alt = getInterpreter().adaptivePredict(_input,181,_ctx);
			} while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER );
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			_errHandler.reportError(this, re);
			_errHandler.recover(this, re);
		}
		finally {
			exitRule();
		}
		return _localctx;
	}

@pbludov
Copy link
Member

pbludov commented Mar 22, 2022

Related Spotbugs issue: spotbugs/spotbugs#1919
Already fixed, the error should be gone on the next release of Spotbugs.

pbludov added a commit to pbludov/checkstyle that referenced this issue Mar 22, 2022
@romani
Copy link
Member Author

romani commented Mar 27, 2022

still issue , noted during release build

@rnveach
Copy link
Member

rnveach commented Apr 17, 2022

Issue still valid.

@pbludov
Copy link
Member

pbludov commented Apr 17, 2022

More details: the root case is the method com.puppycrawl.tools.checkstyle.grammar.javadoc.JavadocParser.TextContext#accept generated by ANTLR

		public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
			if ( visitor instanceof JavadocParserVisitor ) return ((JavadocParserVisitor<? extends T>)visitor).visitText(this);
			else return visitor.visitChildren(this);
		}

@pbludov
Copy link
Member

pbludov commented Apr 17, 2022

I'm trying to set up minimal repro and found another (maybe unrelated) issue.
Anyway, there is something uncovered between CAST and RET in the Spotbugs code.

@pbludov pbludov self-assigned this Apr 17, 2022
@pbludov
Copy link
Member

pbludov commented Apr 18, 2022

Finally got a repro: spotbugs/spotbugs#2019

@rnveach
Copy link
Member

rnveach commented Apr 18, 2022

@pbludov Unrelated to the issue, but how did you print the bytecode for the issue you made in spotbugs?

@pbludov
Copy link
Member

pbludov commented Apr 19, 2022

@pbludov Unrelated to the issue, but how did you print the bytecode for the issue you made in spotbugs?

I used two commands to prepare the repro:

$ javac -g TestClass.java

Option -g is important here. The built class can be analyzed with Spotbugs.

$ javap -c -l TestClass.class

To produce the bytecode dump. But the bytecode for the Spotbugs issue was created with IDEA. There is option "Show bytecode" in the "View" menu. See this topic for more information.

@rnveach
Copy link
Member

rnveach commented May 21, 2022

@romani romani closed this as completed May 21, 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

3 participants