From 05c598c830d4ff10b926a3f413e8a6129fd4337a Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 8 Sep 2015 18:16:50 +0200 Subject: Stuff --- .../java/org/openslx/imagemaster/util/Util.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/main/java/org/openslx/imagemaster/util') diff --git a/src/main/java/org/openslx/imagemaster/util/Util.java b/src/main/java/org/openslx/imagemaster/util/Util.java index ca595b5..79589c4 100644 --- a/src/main/java/org/openslx/imagemaster/util/Util.java +++ b/src/main/java/org/openslx/imagemaster/util/Util.java @@ -40,6 +40,28 @@ public class Util } } + /** + * Check if the given object is null, abort program if true. + * An optional message to be printed can be passed. A stack trace + * will be printed, too. Finally the application terminates with + * exit code 2. + * + * This comes in handy if something must not be null, and you want + * user friendly output. A perfect example would be reading settings + * from a config file. You can use this on mandatory fields. + * + * @param something the object to compare to null + * @param message the message to be printed if something is null + */ + public static void notNullFatal( int number, String message ) + { + if ( number == 0 ) { + if ( message != null ) + log.fatal( "[NOTNULL] " + message, new NullPointerException() ); + System.exit( 2 ); + } + } + /** * Check if String is null or empty, abort program if so. * An optional message to be printed can be passed. A stack trace -- cgit v1.2.3-55-g7522