Avoid NPE on getResourceAsStream() calls

When the resource i.g. properties file is not available the getResourceAsStream() returns null and this cuauses unhandled NPE.
This commit is contained in:
Sergey Ponomarev 2025-07-20 11:48:01 +03:00 committed by Guus der Kinderen
parent 5349f7b519
commit 9c888f4fef
4 changed files with 12 additions and 4 deletions

View File

@ -40,7 +40,9 @@ public class ConfigurationRes {
try try
{ {
InputStream resourceAsStream = cl.getResourceAsStream( "configuration.properties" ); InputStream resourceAsStream = cl.getResourceAsStream( "configuration.properties" );
prb.load( resourceAsStream ); if (resourceAsStream != null) {
prb.load( resourceAsStream );
}
} }
catch ( IOException e ) catch ( IOException e )
{ {

View File

@ -155,7 +155,9 @@ public class Default {
try try
{ {
InputStream resourceAsStream = cl.getResourceAsStream( "default.properties" ); InputStream resourceAsStream = cl.getResourceAsStream( "default.properties" );
prb.load( resourceAsStream ); if (resourceAsStream != null) {
prb.load( resourceAsStream );
}
} }
catch ( IOException e ) catch ( IOException e )
{ {

View File

@ -37,7 +37,9 @@ public class SoundsRes {
try try
{ {
InputStream resourceAsStream = cl.getResourceAsStream( "sounds.properties" ); InputStream resourceAsStream = cl.getResourceAsStream( "sounds.properties" );
prb.load( resourceAsStream ); if (resourceAsStream != null) {
prb.load( resourceAsStream );
}
} }
catch ( IOException e ) catch ( IOException e )
{ {

View File

@ -338,7 +338,9 @@ public class SparkRes {
prb = new Properties(); prb = new Properties();
try { try {
InputStream resourceAsStream = cl.getResourceAsStream("spark.properties"); InputStream resourceAsStream = cl.getResourceAsStream("spark.properties");
prb.load(resourceAsStream); if (resourceAsStream != null) {
prb.load(resourceAsStream);
}
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }