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

[Switch Expression] NPE in StackMapFrameCodeStream.recordExpressionType #2072

Closed
rfcom opened this issue Feb 28, 2024 · 4 comments · Fixed by #2171
Closed

[Switch Expression] NPE in StackMapFrameCodeStream.recordExpressionType #2072

rfcom opened this issue Feb 28, 2024 · 4 comments · Fixed by #2171
Assignees

Comments

@rfcom
Copy link

rfcom commented Feb 28, 2024

java.lang.NullPointerException: Cannot read field "id" because "typeBinding" is null
	at org.eclipse.jdt.internal.compiler.codegen.StackMapFrameCodeStream.recordExpressionType(StackMapFrameCodeStream.java:175)
	at org.eclipse.jdt.internal.compiler.ast.SwitchStatement.generateCode(SwitchStatement.java:933)
	at org.eclipse.jdt.internal.compiler.ast.SwitchExpression.generateCode(SwitchExpression.java:331)
	at org.eclipse.jdt.internal.compiler.ast.Statement.generateArguments(Statement.java:443)
	at org.eclipse.jdt.internal.compiler.ast.AllocationExpression.generateCode(AllocationExpression.java:217)
	at org.eclipse.jdt.internal.compiler.ast.ReturnStatement.generateCode(ReturnStatement.java:214)
	at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:358)
	at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:292)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:759)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:803)
	at org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression.generateCode(QualifiedAllocationExpression.java:250)
	at org.eclipse.jdt.internal.compiler.ast.ReturnStatement.generateCode(ReturnStatement.java:214)
	at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:358)
	at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:292)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:759)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:829)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.generateCode(CompilationUnitDeclaration.java:414)
	at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:915)
	at org.eclipse.jdt.internal.compiler.ProcessTaskManager.run(ProcessTaskManager.java:145)
	at java.base/java.lang.Thread.run(Thread.java:833)

https://git.eclipse.org/r/plugins/gitiles/jdt/eclipse.jdt.core/+/master/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/StackMapFrameCodeStream.java

	@Override
	public void recordExpressionType(TypeBinding typeBinding, int delta, boolean adjustStackDepth) {
		if (adjustStackDepth) {
			// optimized goto
			// the break label already adjusted the stack depth (-1 or -2 depending on the return type)
			// we need to adjust back to what it was
			switch (typeBinding.id) {
				case TypeIds.T_long:
				case TypeIds.T_double:
					this.stackDepth += 2;
					break;
				case TypeIds.T_void:
					break;
				default:
					this.stackDepth++;
					break;
			}
		}
	}
@srikanth-sankaran
Copy link
Contributor

Stack trace is somewhat useful - but a reproducible test case will be very welcome.

@srikanth-sankaran srikanth-sankaran added the needinfo Further information is requested label Feb 28, 2024
@iloveeclipse
Copy link
Member

@rfcom : could you please attach the source code that shows the problem?

@srikanth-sankaran : I assume something you will address anyway during switch refactoring work, right? The code in question that fails with NPE is very old, probably not a recent regression.

@srikanth-sankaran
Copy link
Contributor

@rfcom : could you please attach the source code that shows the problem?

@srikanth-sankaran : I assume something you will address anyway during switch refactoring work, right? The code in question that fails with NPE is very old, probably not a recent regression.

Yes, I will follow up.

@srikanth-sankaran srikanth-sankaran self-assigned this Feb 28, 2024
@srikanth-sankaran srikanth-sankaran changed the title NPE in StackMapFrameCodeStream.recordExpressionType [Switch Expression] NPE in StackMapFrameCodeStream.recordExpressionType Feb 28, 2024
@srikanth-sankaran
Copy link
Contributor

StackMapFrameCodeStream.recordExpressionType is dead! Long live StackMapFrameCodeStream.recordExpressionType! 😀

This was part of the ad-hoc stack size computation that #2171 attempts to eliminate with a streamlined and structured stack size tracking across branch arcs.

The method where the NPE is reported doesn't exist anymore and so the problem has been incinerated.

Closing as fixed by #2171

@srikanth-sankaran srikanth-sankaran removed the needinfo Further information is requested label Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants