From 56ebb322d4c1f447f64580ad7be499989f49b796 Mon Sep 17 00:00:00 2001 From: Dominique Marcadet <Dominique.Marcadet@centralesupelec.fr> Date: Mon, 30 Mar 2020 21:35:45 +0200 Subject: [PATCH] avoid other potential NPE --- .../iec61850/scl/util/SclUtilities.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/util/SclUtilities.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/util/SclUtilities.java index b1535d6..12c33f5 100644 --- a/fr.centralesupelec.edf.riseclipse.iec61850.scl/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/util/SclUtilities.java +++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/util/SclUtilities.java @@ -60,6 +60,9 @@ public class SclUtilities { } public static Pair< IED, Integer > getIED( @NonNull SCL scl, @NonNull String iedName ) { + // protect against NPE + if( scl == null ) return Pair.of( null, 0 ); + List< IED > res = scl .getIED() @@ -74,6 +77,9 @@ public class SclUtilities { } public static Pair< AccessPoint, Integer > getAccessPoint( @NonNull IED ied, @NonNull String apName ) { + // protect against NPE + if( ied == null ) return Pair.of( null, 0 ); + List< AccessPoint > res = ied .getAccessPoint() @@ -88,9 +94,11 @@ public class SclUtilities { } public static Pair< LDevice, Integer > getLDevice( @NonNull AccessPoint accessPoint, @NonNull String ldInst ) { - if( accessPoint.getServer() == null ) { - return Pair.of( null, 0 ); - } + // protect against NPE + if( ldInst == null ) return Pair.of( null, 0 ); + if( accessPoint == null ) return Pair.of( null, 0 ); + if( accessPoint.getServer() == null ) return Pair.of( null, 0 ); + List< LDevice > res = accessPoint .getServer() @@ -106,6 +114,10 @@ public class SclUtilities { } public static Pair< LDevice, Integer > getLDevice( @NonNull IED ied, @NonNull String ldInst ) { + // protect against NPE + if( ldInst == null ) return Pair.of( null, 0 ); + if( ied == null ) return Pair.of( null, 0 ); + List< LDevice > res = ied .getAccessPoint() @@ -128,9 +140,11 @@ public class SclUtilities { if( "LLN0".equals( lnClass )) { return Pair.of( lDevice.getLN0(), ( lDevice.getLN0() == null ) ? 0 : 1 ); } + // Null checks must be done as annotation-based null analysis is not enabled (issue #64) if( lnClass == null ) return Pair.of( null, 0 ); if( lnInst == null ) return Pair.of( null, 0 ); + List< LN > res = lDevice .getLN() -- GitLab