Skip to content

Commit fe6dafe

Browse files
committed
fixes #449
1 parent fce593d commit fe6dafe

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/main/java/net/sf/jsqlparser/expression/ExpressionVisitorAdapter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,15 @@ public void visit(SubSelect subSelect) {
227227

228228
@Override
229229
public void visit(CaseExpression expr) {
230-
expr.getSwitchExpression().accept(this);
230+
if (expr.getSwitchExpression()!=null) {
231+
expr.getSwitchExpression().accept(this);
232+
}
231233
for (Expression x : expr.getWhenClauses()) {
232234
x.accept(this);
233235
}
234-
expr.getElseExpression().accept(this);
236+
if (expr.getElseExpression() != null) {
237+
expr.getElseExpression().accept(this);
238+
}
235239
}
236240

237241
@Override

src/test/java/net/sf/jsqlparser/expression/ExpressionVisitorAdapterTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,5 +188,26 @@ public void testSubSelectExpressionProblem() throws JSQLParserException {
188188
fail();
189189
}
190190
}
191+
192+
@Test
193+
public void testCaseWithoutElse() throws JSQLParserException {
194+
Expression expr = CCJSqlParserUtil.parseExpression("CASE WHEN 1 then 0 END");
195+
ExpressionVisitorAdapter adapter = new ExpressionVisitorAdapter();
196+
expr.accept(adapter);
197+
}
198+
199+
@Test
200+
public void testCaseWithoutElse2() throws JSQLParserException {
201+
Expression expr = CCJSqlParserUtil.parseExpression("CASE WHEN 1 then 0 ELSE -1 END");
202+
ExpressionVisitorAdapter adapter = new ExpressionVisitorAdapter();
203+
expr.accept(adapter);
204+
}
205+
206+
@Test
207+
public void testCaseWithoutElse3() throws JSQLParserException {
208+
Expression expr = CCJSqlParserUtil.parseExpression("CASE 3+4 WHEN 1 then 0 END");
209+
ExpressionVisitorAdapter adapter = new ExpressionVisitorAdapter();
210+
expr.accept(adapter);
211+
}
191212

192213
}

0 commit comments

Comments
 (0)