Closed alban-auzeill closed 4 months ago
We plan to stop supporting Java targets < 1.8 in the current release, see #2536.
(1) Do you still get the problem if this line
options.put("org.eclipse.jdt.core.compiler.codegen.simulateOperandStack", "enabled");
is deleted ?
I am surprised to see this option being enabled! This is a purely internal option that forces exercising of certain code paths and is not meant to be a user option. This internal option has served its purpose and is withdrawn - on master it doesn't exist.
In any case, on master the operand stack creation code looks like:
private OperandStack createOperandStack(CompilerOptions compilerOptions) {
if ((this.generateAttributes & (ClassFileConstants.ATTR_VARS
| ClassFileConstants.ATTR_STACK_MAP_TABLE
| ClassFileConstants.ATTR_STACK_MAP)) == 0) {
return new OperandStack.NullStack();
}
return this.targetLevel >= ClassFileConstants.JDK1_6 && JavaFeature.SWITCH_EXPRESSIONS.isSupported(compilerOptions.sourceLevel, compilerOptions.enablePreviewFeatures) ?
new OperandStack(this.classFile) : new OperandStack.NullStack();
}
OIOW, a functional operand stack is simulated only when target level >=1.6 - which means in your snippet's case it would only create the dummy NullStack
which acts as a sink for any value including null.
org.eclipse.jdt.internal.compiler.codegen.OperandStack.push(TypeBinding)
starts outs with:
if (typeBinding == null) {
throw new AssertionError("Attempt to push null on operand stack!"); //$NON-NLS-1$
}
while org.eclipse.jdt.internal.compiler.codegen.OperandStack.NullStack.push(TypeBinding)
simply says return
So I don't see this problem happening on the evolving 4.33 branch
(2) As @iloveeclipse mentioned, in any case soon levels 1.7 and below are not supported.
So I plan to close this as can't repro
- unless you have a scenario that manifests the problem on master.
Summary: things have already moved along quite a ways that this is not an issue on master HEAD on date and for sometime.
(1) Do you still get the problem if this line options.put("org.eclipse.jdt.core.compiler.codegen.simulateOperandStack", "enabled"); is deleted ?
No, if one of those conditions is true, the problem is not present:
org.eclipse.jdt.core.compiler.codegen.simulateOperandStack
!= "enabled"org.eclipse.jdt.core.compiler.codegen.targetPlatform
> 1.5org.eclipse.jdt.core.compiler.debug.localVariable
== "generate"I am surprised to see this option being enabled!
It was not intentional. It is due to misuse of ASTParser#setCompilerOptions(options);
.
The tool I'm maintaining initializes options
using new HashMap<>()
instead of JavaCore. getOptions()
(see here).
Now that I have read the setCompilerOptions
javadoc, I understand our mistake.
That said, I'm surprised that a missing property in options
like org.eclipse.jdt.core.compiler.codegen.simulateOperandStack
is enabled
when missing.
It would be more forgivable if missing properties could have the same default as JavaCore.getOptions()
.
The same problem applies to org.eclipse.jdt.core.compiler.codegen.targetPlatform
; we didn't want to provide an unsupported version 1.5 or below. But while parsing Java 21 source code we only define org.eclipse.jdt.core.compiler.compliance
and org.eclipse.jdt.core.compiler.source
and didn't provide any value for org.eclipse.jdt.core.compiler.codegen.targetPlatform
.
We will fix our mistake by using JavaCore.setComplianceOptions(JavaCore.VERSION_21, options);
That's why I mentioned in the issue description that it's a corner case. I believe that once we fix our usage of the compiler options, we should not be impacted by this issue.
Thanks for the detailed explanation @alban-auzeill - I'll close this without change since as already documented 1.7 and below support is going away very soon.
Note
The reproducer is a corner case where the compliance java version is > '8' and the target platform version < '1.5'. It should not happen often, but it may help to fix a bug that was difficult to reproduce otherwise, like the closed issue #2484
Reproducer
On the
R4_32_maintenance
branch Add the following unit test toorg.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java
Run the test:
The test fails with the following error: