Author: bpoussin Date: 2010-10-28 11:54:34 +0200 (Thu, 28 Oct 2010) New Revision: 1941 Url: http://nuiton.org/repositories/revision/nuiton-utils/1941 Log: accept null argument for parse method Modified: trunk/src/main/java/org/nuiton/util/ApplicationConfig.java Modified: trunk/src/main/java/org/nuiton/util/ApplicationConfig.java =================================================================== --- trunk/src/main/java/org/nuiton/util/ApplicationConfig.java 2010-10-27 10:59:17 UTC (rev 1940) +++ trunk/src/main/java/org/nuiton/util/ApplicationConfig.java 2010-10-28 09:54:34 UTC (rev 1941) @@ -546,7 +546,7 @@ // iterate with Properties method and not with Hashtable method to // prevent missed value with chained Properties object for (String key : defaults.stringPropertyNames()) { - this.defaults.put(key, defaults.getProperty(key)); + setDefaultOption(key, defaults.getProperty(key)); } } @@ -1431,6 +1431,9 @@ * @throws ArgumentsParserException if parsing failed */ public void parse(String[] args) throws ArgumentsParserException { + if (args == null) { + args = new String[0]; + } try { Map<String, Method> methods = getMethods();
Le Thu, 28 Oct 2010 11:54:34 +0200 (CEST), bpoussin@users.nuiton.org a écrit :
if (args == null) { + args = new String[0]; + } Vaut mieux éviter des allocation de tableaux vide.
Mieux vaut utiliser une constante : public static final String[] EMPTY_STRING_ARRAY = new String[0]; puis args = EMPTY_STRING_ARRAY; Cà évite des allocations mémoire pour rien ;) -- Tony Chemit -------------------- tél: +33 (0) 2 40 50 29 28 email: chemit@codelutin.com http://www.codelutin.com
participants (2)
-
bpoussin@users.nuiton.org -
chemit