Closed snuyanzin closed 1 year ago
Reproduces with
Object o = true ? null : "";
See org.codehaus.commons.compiler.tests.ReportedBugsTest.testIssue188()
.
Fixed it... please test!
amazing, thank you will have a look soon
Flink tests are still failing with this issue.
It looks like it is fixed for Object o = true ? null : "";
However it is still reproducible when this expression is a passing arg like
String s1 = new StringBuilder().append(true ? (String) null : "abc").toString(); // ok
String s2 = new StringBuilder().append(true ? null : "abc").toString(); // <= InternalCompilerException
Sigh... I’ll look into it.
Hi @aunkrig I just want to share some findings regarding this issue. After some debugging I realized that such condition
if (cv == null && rv instanceof ConditionalExpression) {
this.tryNullConversion(IClass.NULL, this.getType2((ConditionalExpression)rv));
}
in org.codehaus.janino.UnitCompiler#compileGetValue(org.codehaus.janino.Java.Rvalue)
helps to pass tests.
Also there is a commit in my fork, where changes could be seen https://github.com/snuyanzin/janino/commit/2dff5b4030e617223cc81819f7ace4951eabc5e7
WDYT how bad/good is this approach?
I fixed it differently... please test.
It behaves a bit strange.
From one side mvn clean verify
for janino-parent fails with
Tests in error:
ReportedBugsTest.testIssue188:1662->CommonsCompilerTestSuite.assertScriptExecutable:215 » Compile
on lines
this.assertScriptExecutable("String s1 = new StringBuilder().append(true ? (String) null : \"abc\").toString(); // ok");
this.assertScriptExecutable("String s2 = new StringBuilder().append(true ? null : \"abc\").toString(); // <= InternalCompilerException");
At the same time now it passes Flink tests...
Strange... in my development environment, a different test fails now:
org.codehaus.commons.compiler.tests.JlsTest.test_9_3_1__Initialization_of_Fields_in_Interfaces__2(JlsTest.java:802)
this.assertClassBodyUncookable("public final static float x = 0D;");
fails with the JDK (not the Janino!) implementation with JRE 8:
Line 1, Column 31: incompatible types: possible lossy conversion from double to float (compiler.err.prob.found.req)
The reason being is that the compile error handling of the JDK implementation chokes on the first compilation error:
The reason appears to be that org.codehaus.commons.compiler.jdk.Compiler.compile(...).new DiagnosticListener() {...}.report(Diagnostic<? extends JavaFileObject>)
(Line 350) attempts to "tunnel" the compilation error through the JDK compiler via a RuntimeException
, and that doesn't work (at least with JDK 8), because com.sun.tools.javac.code.Symbol.VarSymbol.getConstValue()
catches Exception
and throws an AssertionError
.
But now let's turn to testIssue188()
.
Ah, found the reason for the testIssue188()
test error:
JAVAC does not like source code that ends with a C++-style comment and no line terminator.
Change test case accordingly.
Please test.
checked locally now both Janino and Flink tests are passing
After update to Calcite 1.28 (janino 3.1.6) there is a failure (also reproducible with 3.1.8). It complains for these lines from generated code
The interesting thing is that if I put explicit cast of
null
to the expected type then the issue is disappeared.the full stacktrace is