Skip to content

Commit

Permalink
Empty ListExpression#genCode will throw npe (#1063)
Browse files Browse the repository at this point in the history
* fix and ut

* change

---------

Co-authored-by: 陈亚东 <[email protected]>
  • Loading branch information
farmerworking and 陈亚东 authored Nov 3, 2023
1 parent 694f7a6 commit fa2787a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions java/fury-core/src/main/java/io/fury/codegen/Expression.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ public TypeToken<?> type() {

@Override
public ExprCode doGenCode(CodegenContext ctx) {
if (last == null) {
return new ExprCode(null, null, null);
}

StringBuilder codeBuilder = new StringBuilder();
boolean hasCode = false;
for (Expression expr : expressions) {
Expand Down
11 changes: 11 additions & 0 deletions java/fury-core/src/test/java/io/fury/codegen/ExpressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package io.fury.codegen;

import static io.fury.type.TypeUtils.PRIMITIVE_SHORT_TYPE;
import static org.testng.Assert.assertNull;

import io.fury.codegen.Expression.ListExpression;
import io.fury.codegen.Expression.Literal;
import io.fury.codegen.Expression.Reference;
import io.fury.codegen.Expression.Return;
Expand Down Expand Up @@ -64,4 +66,13 @@ public void testIfExpression() {
Assert.assertEquals(code, expected);
}
}

@Test
public void testListExpression() {
{
ListExpression exp = new ListExpression();
String code = exp.genCode(new CodegenContext()).code();
assertNull(code);
}
}
}

0 comments on commit fa2787a

Please sign in to comment.