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
{
InputStream resourceAsStream = cl.getResourceAsStream( "configuration.properties" );
prb.load( resourceAsStream );
if (resourceAsStream != null) {
prb.load( resourceAsStream );
}
}
catch ( IOException e )
{

View File

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

View File

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

View File

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