File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed
main/java/net/sf/jsqlparser/expression
test/java/net/sf/jsqlparser/expression Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments