From e934726c4b68b69e529964856d7ccc9ebd253457 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 14 Nov 2024 16:38:14 +0100 Subject: [PATCH] revert convert Object->String, causes NPE problems --- .../hs/office/scenarios/TemplateResolver.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/TemplateResolver.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/TemplateResolver.java index 7197e900..977c2f13 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/TemplateResolver.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/TemplateResolver.java @@ -22,25 +22,25 @@ public class TemplateResolver { enum PlaceholderPrefix { RAW('%') { @Override - String convert(final String value, final Resolver resolver) { + String convert(final Object value, final Resolver resolver) { return value != null ? value.toString() : ""; } }, JSON_QUOTED('$'){ @Override - String convert(final String value, final Resolver resolver) { + String convert(final Object value, final Resolver resolver) { return jsonQuoted(value); } }, URI_ENCODED('&'){ @Override - String convert(final String value, final Resolver resolver) { + String convert(final Object value, final Resolver resolver) { return value != null ? URLEncoder.encode(value.toString(), StandardCharsets.UTF_8) : ""; } }, COMMENT('#'){ @Override - String convert(final String value, final Resolver resolver) { + String convert(final Object value, final Resolver resolver) { return resolver == DROP_COMMENTS ? "" : value.toString(); } }; @@ -59,7 +59,7 @@ public class TemplateResolver { return Arrays.stream(values()).filter(p -> p.prefixChar == givenChar).findFirst().orElseThrow(); } - abstract String convert(final String value, final Resolver resolver); // FIXME: why Object and not String? + abstract String convert(final Object value, final Resolver resolver); } private final static Pattern pattern = Pattern.compile(",(\\s*})", Pattern.MULTILINE); @@ -136,7 +136,7 @@ public class TemplateResolver { } } final var content = new TemplateResolver(placeholder.toString(), properties).resolve(resolver); - final var value = intro != '#' ? propVal(content).toString() : content; + final var value = intro != '#' ? propVal(content) : content; resolved.append( PlaceholderPrefix.ofPrefixChar(intro).convert(value, resolver) ); @@ -150,12 +150,12 @@ public class TemplateResolver { } else if (nameExpression.contains(IF_NOT_FOUND_SYMBOL)) { final var parts = StringUtils.split(nameExpression, IF_NOT_FOUND_SYMBOL); return Arrays.stream(parts).filter(Objects::nonNull).findFirst().orElseGet(() -> { - if ( parts[parts.length-1].isEmpty() ) { - // => whole expression ends with IF_NOT_FOUND_SYMBOL, thus last null element was optional - return null; - } - // => last alternative element in expression was null and not optional - throw new IllegalStateException("Missing required value in property-chain: " + nameExpression); + if ( parts[parts.length-1].isEmpty() ) { + // => whole expression ends with IF_NOT_FOUND_SYMBOL, thus last null element was optional + return null; + } + // => last alternative element in expression was null and not optional + throw new IllegalStateException("Missing required value in property-chain: " + nameExpression); }); } else { final var val = properties.get(nameExpression);