Skip to content

Commit

Permalink
Merge pull request #284 from pzygielo/message
Browse files Browse the repository at this point in the history
Fix NullPointerException on null outcome
  • Loading branch information
arjantijms committed Sep 2, 2020
2 parents 815b0fd + 7cce803 commit bbd31d3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ public static boolean evalImmediate(ELProcessor getELProcessor, String expressio
if (outcome instanceof Boolean) {
return (Boolean) outcome;
}

throw new IllegalStateException(
"Expression " + expression + " should evaluate to boolean but evaluated to " +
outcome == null? " null" : (outcome.getClass() + " " + outcome));

throw new IllegalStateException(buildNonBooleanOutcomeMessage(outcome, expression));
}

static String buildNonBooleanOutcomeMessage(Object outcome, String expression) {
return "Expression " + expression + " should evaluate to boolean but evaluated to " +
(outcome == null? " null" : (outcome.getClass() + " " + outcome));
}

public static int evalImmediate(String expression, int defaultValue) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.glassfish.soteria.cdi;

import static org.junit.Assert.*;
import org.junit.Test;

public class AnnotationELPProcessorTest {
@Test
public void shouldBuildExpectedMessageForNullOutcome() {
String msg = AnnotationELPProcessor.buildNonBooleanOutcomeMessage(null, "abc");

assertEquals("Expression abc should evaluate to boolean but evaluated to null", msg);
}

@Test
public void shouldBuildExpectedMessageForNonBooleanOutcome() {
String msg = AnnotationELPProcessor.buildNonBooleanOutcomeMessage(1, "ijk");

assertEquals("Expression ijk should evaluate to boolean but evaluated to class java.lang.Integer 1", msg);
}

}

0 comments on commit bbd31d3

Please sign in to comment.