diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/platform/PlatformModule.java b/src/main/java/com/redhat/rhjmc/containerjfr/platform/PlatformModule.java index 26c68cafae..e1cda38a46 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/platform/PlatformModule.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/platform/PlatformModule.java @@ -106,20 +106,25 @@ static AuthManager provideAuthManager( @Singleton static PlatformDetectionStrategy providePlatformStrategy( Logger logger, Set> strategies, Environment env) { + PlatformDetectionStrategy strat = null; if (env.hasEnv(PLATFORM_STRATEGY_ENV_VAR)) { String platform = env.getEnv(PLATFORM_STRATEGY_ENV_VAR); logger.info( String.format( "Selecting configured PlatformDetectionStrategy \"%s\"", platform)); - for (PlatformDetectionStrategy strat : strategies) { - if (Objects.equals(platform, strat.getClass().getCanonicalName())) { - return strat; + for (PlatformDetectionStrategy s : strategies) { + if (Objects.equals(platform, s.getClass().getCanonicalName())) { + strat = s; + break; } } - throw new RuntimeException( - String.format("Selected PlatformDetectionStrategy \"%s\" not found", platform)); + if (strat == null) { + throw new RuntimeException( + String.format( + "Selected PlatformDetectionStrategy \"%s\" not found", platform)); + } } - PlatformDetectionStrategy strat = + strat = strategies.stream() // reverse sort, higher priorities should be earlier in the stream .sorted((a, b) -> Integer.compare(b.getPriority(), a.getPriority()))