Skip to content

Commit

Permalink
Merge pull request quarkusio#21733 from mkouba/qute-template-extensio…
Browse files Browse the repository at this point in the history
…ns-null-param

Qute namespace extensions - fix a NPE when a param resolves to null
  • Loading branch information
geoand authored Nov 29, 2021
2 parents 5f43bed + 10656aa commit 0b77de7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static io.quarkus.qute.TemplateExtension.ANY;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.EnumSet;
import java.util.Set;
Expand Down Expand Up @@ -38,6 +39,11 @@ public void testTemplateExtensions() {
engine.parse("{str:format('%s',1)}").render());
assertEquals("olleh",
engine.parse("{str:reverse('hello')}").render());
try {
engine.parse("{str:reverse(null)}").render();
fail();
} catch (NullPointerException expected) {
}
assertEquals("foolish:olleh",
engine.parse("{str:foolish('hello')}").render());
assertEquals("ONE=ONE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ public boolean parameterTypesMatch(boolean varargs, Class<?>[] types) throws Int
int i = 0;
Class<?> paramType = boxType(types[i]);
while (i < results.length) {
Class<?> resultClass = boxType(getResult(i).getClass());
if (!paramType.isAssignableFrom(resultClass)) {
return false;
Object result = getResult(i);
if (result != null) {
Class<?> resultClass = boxType(result.getClass());
if (!paramType.isAssignableFrom(resultClass)) {
return false;
}
}
if (types.length > ++i) {
paramType = boxType(types[i]);
Expand Down

0 comments on commit 0b77de7

Please sign in to comment.