From 49516c6c0bf95c54893f120cf76c578aa0edf4a7 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 5 Jul 2023 22:33:53 +0200 Subject: [PATCH] Clean up ApiPathParser.URL_FACTORY Use a switch expression and guarantee a @NonNull result. Change-Id: I8a53c1b358f739aa8f4efeb9d36641a3039145cc Signed-off-by: Robert Varga --- .../restconf/api/ApiPathParser.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/protocol/restconf-api/src/main/java/org/opendaylight/restconf/api/ApiPathParser.java b/protocol/restconf-api/src/main/java/org/opendaylight/restconf/api/ApiPathParser.java index ce6f68aad4..0f6d049695 100644 --- a/protocol/restconf-api/src/main/java/org/opendaylight/restconf/api/ApiPathParser.java +++ b/protocol/restconf-api/src/main/java/org/opendaylight/restconf/api/ApiPathParser.java @@ -66,35 +66,36 @@ class ApiPathParser { } } - private static final Supplier URL_FACTORY; + private static final Supplier<@NonNull ApiPathParser> URL_FACTORY; static { // Select the correct parser implementation where consecutive slashes are concerned. We default to lenient // interpretation and treat them as a single slash, but allow this to be overridden through a system property. final String prop = System.getProperty("org.opendaylight.restconf.url.consecutive-slashes", "reject"); final String treatment; - switch (prop) { - case "allow": + URL_FACTORY = switch (prop) { + case "allow" -> { treatment = "are treated as a single slash"; - URL_FACTORY = Lenient::new; - break; - case "debug": + yield Lenient::new; + } + case "debug" -> { treatment = "are treated as a single slash and will be logged"; - URL_FACTORY = () -> new Logging(LOG::debug); - break; - case "warn": + yield () -> new Logging(LOG::debug); + } + case "warn" -> { treatment = "are treated as a single slash and will be warned about"; - URL_FACTORY = () -> new Logging(LOG::warn); - break; - case "reject": + yield () -> new Logging(LOG::warn); + } + case "reject" -> { treatment = "will be rejected"; - URL_FACTORY = ApiPathParser::new; - break; - default: + yield ApiPathParser::new; + } + default -> { LOG.warn("Unknown property value '{}', assuming 'reject'", prop); treatment = "will be rejected"; - URL_FACTORY = ApiPathParser::new; - } + yield ApiPathParser::new; + } + }; LOG.info("Consecutive slashes in REST URLs {}", treatment); } -- 2.36.6