Example usage for java.lang IllegalArgumentException getMessage

List of usage examples for java.lang IllegalArgumentException getMessage

Introduction

In this page you can find the example usage for java.lang IllegalArgumentException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.moviejukebox.tools.DateTimeTools.java

/**
 * Convert a date to a specific format//  www.  ja  v  a 2 s. c om
 *
 * @param dateToParse
 * @return
 */
public static String parseDateToString(String dateToParse) {
    try {
        return convertDateToString(parseStringToDate(dateToParse), getDateFormatString());
    } catch (IllegalArgumentException ex) {
        LOG.debug("Failed to parse date '{}', error: {}", dateToParse, ex.getMessage(), ex);
        return StringUtils.EMPTY;
    }
}

From source file:bachelorthesis.captchabuilder.builder.TextParser.java

/**
 * Parses the string arguments for rendering Text, creates a
 * TextProducer and WordRenderer passes these to the CaptchaBuilder
 *
 * @param buildSequenceOptions the string arguments for adding text
 * @param builder              the CaptchaBuilder Object to be modified
 * <p/>//from  ww  w. j a v  a 2s .c o m
 * @return a modified CaptchaBuilder object
 * <p/>
 * @throws org.apache.commons.cli.ParseException
 * @see CaptchaBuilder
 */
public static CaptchaBuilder parse(String[] buildSequenceOptions, CaptchaBuilder builder)
        throws ParseException {

    for (String textOptionArg : buildSequenceOptions) {
        if (!textOptionArg.isEmpty()) {
            try {
                String[] optionArgs = textOptionArg.split(CaptchaConstants.buildSequencelvl3Delim);
                TextOptions textOptionType = TextOptions.valueOf(optionArgs[0]);
                String[] textOptions = Arrays.copyOfRange(optionArgs, 1, optionArgs.length);

                parseTextOption(textOptionType, textOptions, builder);
            } catch (IllegalArgumentException e) {
                throw new ParseException(e.getMessage());
            }

        }
    }

    //return builder.addText(textProducerBuilder.create(), wordRendererBuilder.create());
    builder.addBuildSequence(textProducerBuilder);
    builder.addBuildSequence(wordRendererBuilder);
    return builder;
}

From source file:com.ingby.socbox.bischeck.cli.CacheCli.java

private static void cli(Boolean supportNull) throws IOException, ConfigurationException {

    ExecuteJEP parser = new ExecuteJEP(); // Create a new parser 

    ConsoleReader console = null;//from   w  w w  .  j  a  va2  s  .co  m
    FileHistory history = null;

    String historyFile = System.getProperty("user.home") + File.separator + HISTORY_FILE;

    try {

        console = new ConsoleReader();
        history = new FileHistory(new File(historyFile));
        console.println("Welcome to Bischeck cache-cli");
        console.println("-----------------------------");

        console.print("- Using bischeck configuration: ");
        console.println(ConfigFileManager.initConfigDir().getAbsolutePath());

        console.print("- Cmd history: ");
        console.println(history.getFile().getAbsolutePath());
        console.print("- Null support in arrays: ");
        console.println(supportNull.toString());

        console.setHistory(history);
        console.println("Execution time is divided in parse/calculate/total time (ms)");
        console.setPrompt(PROMPT);

        // Main loop reading cli commands
        boolean first = true;
        while (true) {
            String line = null;

            try {
                line = console.readLine();
            } catch (IllegalArgumentException ie) {
                console.println(ie.getMessage());
                continue;
            }

            if (line == null || QUIT.equalsIgnoreCase(line) || EXIT.equalsIgnoreCase(line)) {
                break;
            }

            if (line.matches("^list.*")) {
                String[] patternArray = line.split("^list");
                String pattern = "*";
                if (patternArray.length == 2 && !patternArray[1].trim().isEmpty()) {
                    pattern = patternArray[1];
                }

                Map<String, Long> lists = listKeys(pattern.trim());
                if (!lists.isEmpty()) {
                    for (String key : lists.keySet()) {
                        console.print(key);
                        console.print(" : ");
                        console.println(lists.get(key).toString());
                    }
                } else {
                    console.println(NOT_FOUND);
                }

                continue;
            }

            if (HELP.equalsIgnoreCase(line)) {
                showhelp(console);
                continue;
            }

            try {
                if (first) {
                    execute(parser, line);
                    console.println(execute(parser, line));
                    first = false;
                } else {
                    console.println(execute(parser, line));
                }
            } catch (ParseException e) {
                console.println(e.getMessage());
            }
        }
    } finally {
        try {
            TerminalFactory.get().restore();
        } catch (Exception e) {
            console.println("Could not restore " + e.getMessage());
        }
        if (history != null) {
            history.flush();
        }
    }
}

From source file:jongo.JongoUtils.java

/**
 * Calls the JongoConfiguration.instanceOf() method and returns the given instance of {@link jongo.config.JongoConfiguration}
 * @return an instance of {@link jongo.config.JongoConfiguration}
 * @throws StartupException if {@link jongo.config.JongoConfiguration} fails to instantiate.
 *//*w w w .j  ava  2  s  . com*/
public static JongoConfiguration loadConfiguration() throws StartupException {
    JongoConfiguration configuration = null;
    try {
        configuration = JongoConfiguration.instanceOf();
    } catch (IllegalArgumentException e) {
        l.error(e.getMessage());
    }

    if (configuration == null) {
        throw new StartupException("Failed to load configuration", true);
    }

    return configuration;
}

From source file:com.linkedin.drelephant.util.InfoExtractor.java

/**
  * Retrieve the spark properties from SPARK_EXTRA_JAVA_OPTIONS
  *//from  w  w  w.  j a  v  a 2 s .  co  m
  * @param appData the Spark Application Data
  * @return The retrieved Spark properties
  */
public static Properties retrieveSparkProperties(SparkApplicationData appData) {
    Option<String> prop = appData.appConfigurationProperties().get(SPARK_EXTRA_JAVA_OPTIONS);
    Properties properties = new Properties();
    if (prop.isDefined()) {
        try {
            Map<String, String> javaOptions = Utils.parseJavaOptions(prop.get());
            for (String key : javaOptions.keySet()) {
                properties.setProperty(key, unescapeString(javaOptions.get(key)));
            }
        } catch (IllegalArgumentException e) {
            logger.error("Encountered error while parsing java options into urls: " + e.getMessage());
        }
    } else {
        logger.error("Unable to retrieve the scheduler info for application [" + appData.appId()
                + "]. It does not contain [" + SPARK_EXTRA_JAVA_OPTIONS
                + "] property in its spark properties.");
    }
    return properties;
}

From source file:com.github.mavogel.ilias.utils.IOUtils.java

/**
 * Reads and parses a single choice from the user.<br>
 * Handles wrong inputs and ensures the choice is in
 * the range of the possible choices./*  w  w w.ja v  a  2 s  .c om*/
 *
 * @param choices the possible choices
 * @return the choice of the user.
 */
public static int readAndParseSingleChoiceFromUser(final List<?> choices) {
    boolean isCorrectInput = false;
    String line = null;
    int userChoice = -1;

    Scanner scanner = new Scanner(System.in);
    while (!isCorrectInput) {
        try {
            LOG.info("A single choice only! (E.g.: 1)");
            line = StringUtils.deleteWhitespace(scanner.nextLine());
            userChoice = Integer.valueOf(line);
            isCorrectInput = isInRange(choices, userChoice);
        } catch (NumberFormatException nfe) {
            LOG.error("'" + line + "' is not  a number! Try again");
        } catch (IllegalArgumentException iae) {
            LOG.error(iae.getMessage());
        }
    }

    return userChoice;
}

From source file:com.github.mavogel.ilias.utils.IOUtils.java

/**
 * Reads and parses a positive integer.//w w w  .  java 2s .c  o  m
 *
 * @return the positive integer.
 */
public static int readAndParsePositiveInteger() {
    boolean isCorrectInput = false;
    String line = null;
    int positiveInteger = -1;

    Scanner scanner = new Scanner(System.in);
    while (!isCorrectInput) {
        try {
            LOG.info("Enter a positive integer:");
            line = StringUtils.deleteWhitespace(scanner.nextLine());
            positiveInteger = Integer.valueOf(line);
            isCorrectInput = positiveInteger >= 0;
        } catch (NumberFormatException nfe) {
            LOG.error("'" + line + "' is not a positive integer! Try again");
        } catch (IllegalArgumentException iae) {
            LOG.error(iae.getMessage());
        }
    }

    return positiveInteger;
}

From source file:com.microsoft.rest.Validator.java

/**
 * Validates a user provided required parameter to be not null.
 * A {@link ServiceException} is thrown if a property fails the validation.
 *
 * @param parameter the parameter to validate
 * @throws ServiceException failures wrapped in {@link ServiceException}
 *///from  w ww .  j  a va 2 s. co m
public static void validate(Object parameter) throws ServiceException {
    // Validation of top level payload is done outside
    if (parameter == null) {
        return;
    }

    Class parameterType = parameter.getClass();
    if (ClassUtils.isPrimitiveOrWrapper(parameterType) || parameterType.isEnum()
            || ClassUtils.isAssignable(parameterType, LocalDate.class)
            || ClassUtils.isAssignable(parameterType, DateTime.class)
            || ClassUtils.isAssignable(parameterType, String.class)
            || ClassUtils.isAssignable(parameterType, DateTimeRfc1123.class)
            || ClassUtils.isAssignable(parameterType, Period.class)) {
        return;
    }

    Field[] fields = FieldUtils.getAllFields(parameterType);
    for (Field field : fields) {
        field.setAccessible(true);
        JsonProperty annotation = field.getAnnotation(JsonProperty.class);
        Object property;
        try {
            property = field.get(parameter);
        } catch (IllegalAccessException e) {
            throw new ServiceException(e);
        }
        if (property == null) {
            if (annotation != null && annotation.required()) {
                throw new ServiceException(
                        new IllegalArgumentException(field.getName() + " is required and cannot be null."));
            }
        } else {
            try {
                Class propertyType = property.getClass();
                if (ClassUtils.isAssignable(propertyType, List.class)) {
                    List<?> items = (List<?>) property;
                    for (Object item : items) {
                        Validator.validate(item);
                    }
                } else if (ClassUtils.isAssignable(propertyType, Map.class)) {
                    Map<?, ?> entries = (Map<?, ?>) property;
                    for (Map.Entry<?, ?> entry : entries.entrySet()) {
                        Validator.validate(entry.getKey());
                        Validator.validate(entry.getValue());
                    }
                } else if (parameter.getClass().getDeclaringClass() != propertyType) {
                    Validator.validate(property);
                }
            } catch (ServiceException ex) {
                IllegalArgumentException cause = (IllegalArgumentException) (ex.getCause());
                if (cause != null) {
                    // Build property chain
                    throw new ServiceException(
                            new IllegalArgumentException(field.getName() + "." + cause.getMessage()));
                } else {
                    throw ex;
                }
            }
        }
    }
}

From source file:com.nextep.designer.dbgm.mergers.DatatypeMergeHelper.java

public static void addDatatypeComparison(IComparisonItem result, IDatatype source, IDatatype target,
        ComparisonScope scope) {//w w w  . j  a  v a  2 s . c  o m

    // Getting required services
    final IWorkspaceService workspaceService = CorePlugin.getService(IWorkspaceService.class);
    final IDatatypeService datatypeService = CorePlugin.getService(IDatatypeService.class);
    final IWorkspace workspace = workspaceService.getCurrentWorkspace();

    // Getting required provider
    final IDatatypeProvider p = datatypeService.getDatatypeProvider(workspace.getDBVendor());

    // Getting generation vendor (for future datatype conversion)
    final String context = Designer.getInstance().getContext();
    DBVendor generationVendor = workspace.getDBVendor();
    try {
        if (context != null) {
            generationVendor = DBVendor.valueOf(context);
        }
    } catch (IllegalArgumentException e) {
        LOGGER.error("Unknown vendor used for generation '" + context + "', using workspace default : "
                + e.getMessage(), e);
    }

    // Converting datatype to vendor
    final IDatatype src = datatypeService.getDatatype(generationVendor, source);
    final IDatatype tgt = datatypeService.getDatatype(generationVendor, target);

    final Map<String, String> typeMap = p.getEquivalentDatatypesMap();

    if (scope == ComparisonScope.DATABASE && src != null && tgt != null
            && src.getName().toUpperCase().startsWith("ENUM")) {
        // Special enum fix for mysql
        // TODO properly manage enums, deport mysql specific in mysql
        // plugins
        if (tgt.getName().toUpperCase().startsWith("ENUM")) {
            final String srcEnum = src.getName().substring(4);
            final String tgtEnum = tgt.getName().substring(4);
            if (srcEnum.trim().replace(" ", "").equals(tgtEnum.trim().replace(" ", ""))) {
                result.addSubItem(new ComparisonAttribute(ATTR_DATATYPE, tgt.getName(), tgt.getName()));
            } else {
                result.addSubItem(new ComparisonAttribute(ATTR_DATATYPE,
                        src == null ? null : eqType(typeMap, src.getName()),
                        tgt == null ? null : eqType(typeMap, tgt.getName())));
            }
        } else {
            result.addSubItem(
                    new ComparisonAttribute(ATTR_DATATYPE, src == null ? null : eqType(typeMap, src.getName()),
                            tgt == null ? null : eqType(typeMap, tgt.getName())));
        }

    } else {
        result.addSubItem(
                new ComparisonAttribute(ATTR_DATATYPE, src == null ? null : eqType(typeMap, src.getName()),
                        tgt == null ? null : eqType(typeMap, tgt.getName())));
    }
    ComparisonScope dataLengthScope = scope;
    if (src != null && src.getName().indexOf("INT") > -1
            && VersionHelper.getCurrentView().getDBVendor() == DBVendor.MYSQL) {
        dataLengthScope = ComparisonScope.REPOSITORY;
    }
    // Specific definition for CHAR / BYTE length handling
    Integer srcLength = src == null ? null : src.getLength();
    Integer tgtLength = null;
    if (tgt == null) {
        tgtLength = srcLength;
    } else {
        if ((src != null && src.getLengthType() == LengthType.UNDEFINED)
                || (tgt != null && tgt.getLengthType() == LengthType.UNDEFINED)) {
            // If one of source or target is undefined, we keep the value
            tgtLength = tgt.getLength();
        } else {
            // If type of source is different than target (i.e. BYTE vs CHAR
            // or CHAR vs BYTE)
            // We swap
            if (src != null && src.getLengthType() == tgt.getLengthType()) {
                tgtLength = tgt.getLength();
            } else {
                tgtLength = tgt.getAlternateLength();
            }
        }
    }
    if ((src != null && src.getLengthType() == LengthType.CHAR)
            || (tgt != null && tgt.getLengthType() == LengthType.CHAR)) {
        result.addSubItem(
                new ComparisonAttribute(ATTR_DATASIZE_TYPE, src == null ? null : src.getLengthType().name(),
                        tgt == null ? null : tgt.getLengthType().name()));
    }
    if (scope == ComparisonScope.DATABASE) {
        result.addSubItem(new ComparisonAttribute(ATTR_DATASIZE,
                src == null ? null : String.valueOf(srcLength == 0 && tgt != null ? tgtLength : srcLength),
                tgt == null ? null : String.valueOf(tgtLength), dataLengthScope));
    } else if (scope == ComparisonScope.DB_TO_REPOSITORY) {
        result.addSubItem(new ComparisonAttribute(ATTR_DATASIZE, src == null ? null : String.valueOf(srcLength),
                tgt == null ? null : String.valueOf(tgtLength), dataLengthScope));
    } else {
        result.addSubItem(
                new ComparisonAttribute(ATTR_DATASIZE, src == null ? null : String.valueOf(src.getLength()),
                        tgt == null ? null : String.valueOf(tgt.getLength()), dataLengthScope));
    }
    if (scope == ComparisonScope.DATABASE) {
        result.addSubItem(new ComparisonAttribute(ATTR_DATAPRECISION, src == null ? null
                : String.valueOf(
                        src.getPrecision() == 0 && tgt != null ? tgt.getPrecision() : src.getPrecision()),
                tgt == null ? null : String.valueOf(tgt.getPrecision())));
    } else {
        result.addSubItem(new ComparisonAttribute(ATTR_DATAPRECISION,
                src == null ? null : String.valueOf(src.getPrecision()),
                tgt == null ? null : String.valueOf(tgt.getPrecision())));
    }
    result.addSubItem(
            new ComparisonAttribute(ATTR_DATAUNSIGNED, src == null ? null : Boolean.toString(src.isUnsigned()),
                    tgt == null ? null : Boolean.toString(tgt.isUnsigned())));
}

From source file:com.baasbox.controllers.File.java

@With({ UserCredentialWrapFilter.class, ConnectToDBFilter.class, ExtractQueryParameters.class })
public static Result grantOrRevokeToRole(String id, String rolename, String action, boolean grant) {
    try {/*from  www  . j a v  a  2 s. c o  m*/
        Permissions permission = PermissionsHelper.permissionsFromString.get(action.toLowerCase());
        if (grant)
            FileService.grantPermissionToRole(id, permission, rolename);
        else
            FileService.revokePermissionToRole(id, permission, rolename);
    } catch (IllegalArgumentException e) {
        return badRequest(e.getMessage());
    } catch (RoleNotFoundException e) {
        return notFound("role " + rolename + " not found");
    } catch (OSecurityAccessException e) {
        return Results.forbidden();
    } catch (OSecurityException e) {
        return Results.forbidden();
    } catch (Throwable e) {
        return internalServerError(e.getMessage());
    }
    return ok();
}