This is an automated email from the ASF dual-hosted git repository. lmccay pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/knox.git
The following commit(s) were added to refs/heads/master by this push: new b7f93f6db KNOX-3043 - NullpointerException in calling loadBuildProperties (#917) b7f93f6db is described below commit b7f93f6db3665ccaf77d4de0011cea4e4461c264 Author: senthh <sen...@gmail.com> AuthorDate: Thu Jun 20 19:38:28 2024 +0530 KNOX-3043 - NullpointerException in calling loadBuildProperties (#917) * KNOX-3043 - NullpointerException in calling loadBuildProperties --- .../main/java/org/apache/knox/gateway/GatewayMessages.java | 6 ++++++ .../src/main/java/org/apache/knox/gateway/GatewayServer.java | 11 ++++++++--- .../src/main/java/org/apache/knox/gateway/util/KnoxCLI.java | 12 +++++++++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/GatewayMessages.java b/gateway-server/src/main/java/org/apache/knox/gateway/GatewayMessages.java index 7ce032d8e..7206c6271 100644 --- a/gateway-server/src/main/java/org/apache/knox/gateway/GatewayMessages.java +++ b/gateway-server/src/main/java/org/apache/knox/gateway/GatewayMessages.java @@ -63,6 +63,12 @@ public interface GatewayMessages { @Message( level = MessageLevel.INFO, text = "Loading configuration file {0}" ) void loadingConfigurationFile( String file ); + @Message( level = MessageLevel.INFO, text = "Failed to find configuration file {0}" ) + void failedToFindConfig( String path ); + + @Message( level = MessageLevel.INFO, text = "Failed to find configuration file {0}: {1}" ) + void failedToFindConfig( String path, @StackTrace( level = MessageLevel.INFO ) Exception e ); + @Message( level = MessageLevel.WARN, text = "Failed to load configuration file {0}: {1}" ) void failedToLoadConfig( String path, @StackTrace( level = MessageLevel.DEBUG ) Exception e ); diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/GatewayServer.java b/gateway-server/src/main/java/org/apache/knox/gateway/GatewayServer.java index 01c04cf7f..e81385363 100644 --- a/gateway-server/src/main/java/org/apache/knox/gateway/GatewayServer.java +++ b/gateway-server/src/main/java/org/apache/knox/gateway/GatewayServer.java @@ -304,10 +304,15 @@ public class GatewayServer { private static Properties loadBuildProperties() { Properties properties = new Properties(); - try(InputStream inputStream = GatewayServer.class.getClassLoader().getResourceAsStream( "build.properties" )) { - properties.load( inputStream ); + String BUILD_PROPERTY = "build.properties"; + try(InputStream inputStream = GatewayServer.class.getClassLoader().getResourceAsStream( BUILD_PROPERTY )) { + if (inputStream != null) { + properties.load(inputStream); + } else { + log.failedToFindConfig( BUILD_PROPERTY); + } } catch( IOException e ) { - // Ignore. + log.failedToFindConfig( BUILD_PROPERTY, e ); } return properties; } diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/util/KnoxCLI.java b/gateway-server/src/main/java/org/apache/knox/gateway/util/KnoxCLI.java index 4ce440f4a..b2d3b3059 100644 --- a/gateway-server/src/main/java/org/apache/knox/gateway/util/KnoxCLI.java +++ b/gateway-server/src/main/java/org/apache/knox/gateway/util/KnoxCLI.java @@ -2570,10 +2570,16 @@ public class KnoxCLI extends Configured implements Tool { private static Properties loadBuildProperties() { Properties properties = new Properties(); - try(InputStream inputStream = KnoxCLI.class.getClassLoader().getResourceAsStream( "build.properties" )) { - properties.load(inputStream); + String BUILD_PROPERTY = "build.properties"; + PrintStream out = System.out; + try(InputStream inputStream = KnoxCLI.class.getClassLoader().getResourceAsStream( BUILD_PROPERTY )) { + if (inputStream != null) { + properties.load(inputStream); + } else { + out.println("Failed to find configuration file " + BUILD_PROPERTY); + } } catch( IOException e ) { - // Ignore. + out.println("Failed to find configuration file " + BUILD_PROPERTY + e.getMessage()); } return properties; }