# HG changeset patch # User František Kučera # Date 1388015880 -3600 # Node ID 3b9ec9c23a3784fd3bca4850874eb23c3181a4e8 # Parent 7a88ac6ba40cd98c751864acd1a34f621fd7f07b validation: test if prefix/suffix are valid regular expressions diff -r 7a88ac6ba40c -r 3b9ec9c23a37 java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java Thu Dec 26 00:18:03 2013 +0100 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java Thu Dec 26 00:58:00 2013 +0100 @@ -25,6 +25,8 @@ import java.util.Collection; import java.util.EnumSet; import java.util.List; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; /** * @@ -104,6 +106,11 @@ e.addProblem(new InvalidOptionsException.OptionProblem("Named and numbered parameters can not be used together in one command.")); } + try { + Pattern.compile(namePrefix + "test" + nameSuffix); + } catch (PatternSyntaxException regexException) { + e.addProblem(new InvalidOptionsException.OptionProblem("Ivalid regular expression in name prefix or suffix", regexException)); + } if (e.hasProblems()) { throw e; diff -r 7a88ac6ba40c -r 3b9ec9c23a37 java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Thu Dec 26 00:18:03 2013 +0100 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Thu Dec 26 00:58:00 2013 +0100 @@ -29,6 +29,7 @@ import java.io.IOException; import java.sql.SQLException; import java.util.logging.Level; +import java.util.logging.LogRecord; import java.util.logging.Logger; import javax.xml.bind.JAXBContext; import javax.xml.bind.Unmarshaller; @@ -49,7 +50,7 @@ public static void main(String[] args) { log.log(Level.FINE, "Starting " + Constants.PROGRAM_NAME); int exitCode = EXIT_EXPECTED_ERROR; - + if (args.length == 0) { args = new String[]{CLIParser.Tokens.INFO_HELP}; } @@ -68,7 +69,10 @@ } catch (InvalidOptionsException e) { log.log(Level.SEVERE, "Invalid CLI options", e); for (InvalidOptionsException.OptionProblem p : e.getProblems()) { - log.log(Level.SEVERE, "Option problem: {0}", p.getDescription()); + LogRecord r = new LogRecord(Level.SEVERE, "Option problem: {0}"); + r.setThrown(p.getException()); + r.setParameters(new Object[]{p.getDescription()}); + log.log(r); } } catch (ConfigurationException e) { log.log(Level.SEVERE, "Configuration problem", e); diff -r 7a88ac6ba40c -r 3b9ec9c23a37 java/sql-dk/src/info/globalcode/sql/dk/InvalidOptionsException.java --- a/java/sql-dk/src/info/globalcode/sql/dk/InvalidOptionsException.java Thu Dec 26 00:18:03 2013 +0100 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InvalidOptionsException.java Thu Dec 26 00:58:00 2013 +0100 @@ -44,13 +44,23 @@ public static class OptionProblem { private String description; + private Throwable exception; public OptionProblem(String description) { this.description = description; } + public OptionProblem(String description, Throwable exception) { + this.description = description; + this.exception = exception; + } + public String getDescription() { return description; } + + public Throwable getException() { + return exception; + } } }