Example usage for java.lang IllegalArgumentException toString

List of usage examples for java.lang IllegalArgumentException toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:Main.java

/** ask transformer to pretty-print the output: works with Java built-in XML engine
 * @param transformer will add indent property
 *///from   w ww . j ava2s. c o  m
public static void setTransformerIndent(final Transformer transformer) {
    try {
        transformer.setOutputProperty(XSLT_INDENT_PROP, "4");
    } catch (final IllegalArgumentException e) {
        System.err.println("indent-amount not supported: {}" + e.toString()); // ignore error, don't print stack-trace
    }
}

From source file:org.openecomp.sdc.validation.utils.ValidationConfigurationManager.java

private static Validator validatorInit(ValidatorConfiguration validatorConf) {
    Validator validator = null;/* w w w  . j  a v a  2s .  c  o m*/
    try {
        validator = CommonMethods.newInstance(validatorConf.getImplementationClass(), Validator.class);
    } catch (IllegalArgumentException iae) {
        logger.error("Validator:" + validatorConf.getName() + " Class:" + validatorConf.getImplementationClass()
                + " failed in initialization. error:" + iae.toString() + " trace:"
                + Arrays.toString(iae.getStackTrace()));
    }
    return validator;
}

From source file:org.apache.struts.validator.validwhen.ValidWhen.java

/**
 * Checks if the field matches the boolean expression specified in
 * <code>test</code> parameter.
 *
 * @param bean    The bean validation is being performed on.
 * @param va      The <code>ValidatorAction</code> that is currently being
 *                performed.//from www.j a v a 2  s.  co m
 * @param field   The <code>Field</code> object associated with the
 *                current field being validated.
 * @param errors  The <code>ActionMessages</code> object to add errors to
 *                if any validation errors occur.
 * @param request Current request object.
 * @return <code>true</code> if meets stated requirements,
 *         <code>false</code> otherwise.
 */
public static boolean validateValidWhen(Object bean, ValidatorAction va, Field field, ActionMessages errors,
        Validator validator, HttpServletRequest request) {
    Object form = validator.getParameterValue(Validator.BEAN_PARAM);
    String value = null;
    boolean valid = false;
    int index = -1;

    if (field.isIndexed()) {
        String key = field.getKey();

        final int leftBracket = key.indexOf("[");
        final int rightBracket = key.indexOf("]");

        if ((leftBracket > -1) && (rightBracket > -1)) {
            index = Integer.parseInt(key.substring(leftBracket + 1, rightBracket));
        }
    }

    if (isString(bean)) {
        value = (String) bean;
    } else {
        value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    }

    String test = null;

    try {
        test = Resources.getVarValue("test", field, validator, request, true);
    } catch (IllegalArgumentException ex) {
        String logErrorMsg = sysmsgs.getMessage("validation.failed", "validwhen", field.getProperty(),
                ex.toString());

        log.error(logErrorMsg);

        String userErrorMsg = sysmsgs.getMessage("system.error");

        errors.add(field.getKey(), new ActionMessage(userErrorMsg, false));

        return false;
    }

    // Create the Lexer
    ValidWhenLexer lexer = null;

    try {
        lexer = new ValidWhenLexer(new StringReader(test));
    } catch (Exception ex) {
        String logErrorMsg = "ValidWhenLexer Error for field ' " + field.getKey() + "' - " + ex;

        log.error(logErrorMsg);

        String userErrorMsg = sysmsgs.getMessage("system.error");

        errors.add(field.getKey(), new ActionMessage(userErrorMsg, false));

        return false;
    }

    // Create the Parser
    ValidWhenParser parser = null;

    try {
        parser = new ValidWhenParser(lexer);
    } catch (Exception ex) {
        String logErrorMsg = "ValidWhenParser Error for field ' " + field.getKey() + "' - " + ex;

        log.error(logErrorMsg);

        String userErrorMsg = sysmsgs.getMessage("system.error");

        errors.add(field.getKey(), new ActionMessage(userErrorMsg, false));

        return false;
    }

    parser.setForm(form);
    parser.setIndex(index);
    parser.setValue(value);

    try {
        parser.expression();
        valid = parser.getResult();
    } catch (Exception ex) {
        String logErrorMsg = "ValidWhen Error for field ' " + field.getKey() + "' - " + ex;

        log.error(logErrorMsg);

        String userErrorMsg = sysmsgs.getMessage("system.error");

        errors.add(field.getKey(), new ActionMessage(userErrorMsg, false));

        return false;
    }

    if (!valid) {
        errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));

        return false;
    }

    return true;
}

From source file:com.ibm.mobilefirstplatform.serversdk.java.push.PushNotifications.java

/**
 * If your application server is running on Bluemix, and your push notification service is bound to your application,
 * you can use this method for initialization which will get the credentials from Bluemix's environment variables.
 * // w  w  w . jav a2s  . c o m
 * @param bluemixRegion the Bluemix region where the Push Notifications service is hosted, such as {@link PushNotifications#US_SOUTH_REGION}
 * 
 * @throws IllegalArgumentException if either the push application ID or the secret are not found in the environment variables 
 */
public static void init(String bluemixRegion) {
    String tenantId = null;
    String pushSecret = null;

    tenantId = getApplicationIdFromVCAP();
    pushSecret = getPushSecretFromVCAP();

    if (tenantId != null && pushSecret != null) {
        init(tenantId, pushSecret, bluemixRegion);
    } else {
        IllegalArgumentException exception = new IllegalArgumentException(
                "PushNotifications could not be initialized. Credentials could not be found in environment variables. Make sure they are available, or use the other constructor.");
        logger.log(Level.SEVERE, exception.toString(), exception);
        throw exception;
    }
}

From source file:edu.cuny.cat.market.matching.FourHeapShoutEngine.java

/**
 * Insert a shout into a binary heap./* www  .j av a  2 s . co  m*/
 * 
 * @param heap
 *          The heap to insert into
 * @param shout
 *          The shout to insert
 * 
 */
private static void insertShout(final PriorityBuffer<Shout> heap, final Shout shout)
        throws DuplicateShoutException {
    try {
        heap.add(shout);
    } catch (final IllegalArgumentException e) {
        FourHeapShoutEngine.logger.error(e.toString());
        e.printStackTrace();
        throw new DuplicateShoutException("Duplicate shout: " + shout.toString());
    }
}

From source file:com.alibaba.akita.io.HttpInvoker.java

/**
 * Vversion 2 remoteimageview download impl, use byte[] to decode.
 * Note: Recommanded to use this method instead of version 1.
 * NUM_RETRIES retry.//from   w  ww. ja  va  2 s.  com
 * @param imgUrl
 * @param httpReferer http Referer
 * @return
 * @throws AkServerStatusException
 * @throws AkInvokeException
 */
public static Bitmap getBitmapFromUrl(String imgUrl, String httpReferer, ProgressBar progressBar)
        throws AkServerStatusException, AkInvokeException {
    imgUrl = imgUrl.trim();
    Log.v(TAG, "getBitmapFromUrl:" + imgUrl);

    int timesTried = 1;

    while (timesTried <= NUM_RETRIES) {
        timesTried++;
        try {
            if (progressBar != null) {
                progressBar.setProgress(0);
            }
            HttpGet request = new HttpGet(imgUrl);
            if (httpReferer != null)
                request.addHeader("Referer", httpReferer);
            HttpResponse response = client.execute(request);
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED
                    || statusCode == HttpStatus.SC_ACCEPTED) {
                HttpEntity resEntity = response.getEntity();
                InputStream inputStream = resEntity.getContent();

                byte[] imgBytes = retrieveImageData(inputStream, (int) (resEntity.getContentLength()),
                        progressBar);
                if (imgBytes == null) {
                    SystemClock.sleep(DEFAULT_RETRY_SLEEP_TIME);
                    continue;
                }

                Bitmap bm = null;
                try {
                    bm = ImageUtil.decodeSampledBitmapFromByteArray(imgBytes, 0, imgBytes.length, 682, 682);
                } catch (OutOfMemoryError ooe) {
                    Log.e(TAG, ooe.toString(), ooe);
                    return null; // if oom, no need to retry.
                }
                if (bm == null) {
                    SystemClock.sleep(DEFAULT_RETRY_SLEEP_TIME);
                    continue;
                }
                return bm;
            } else {
                HttpEntity resEntity = response.getEntity();
                throw new AkServerStatusException(response.getStatusLine().getStatusCode(),
                        EntityUtils.toString(resEntity, CHARSET));
            }
        } catch (ClientProtocolException cpe) {
            Log.e(TAG, cpe.toString(), cpe);
            throw new AkInvokeException(AkInvokeException.CODE_HTTP_PROTOCOL_ERROR, cpe.toString(), cpe);
        } catch (IOException ioe) {
            Log.e(TAG, ioe.toString(), ioe);
            throw new AkInvokeException(AkInvokeException.CODE_CONNECTION_ERROR, ioe.toString(), ioe);
        } catch (IllegalStateException ise) {
            Log.e(TAG, ise.toString(), ise);
            throw new AkInvokeException(AkInvokeException.CODE_TARGET_HOST_OR_URL_ERROR, ise.toString(), ise);
        } catch (IllegalArgumentException iae) {
            throw new AkInvokeException(AkInvokeException.CODE_TARGET_HOST_OR_URL_ERROR, iae.toString(), iae);
        } catch (Exception e) {
            throw new AkInvokeException(AkInvokeException.CODE_UNKOWN_ERROR, e.toString(), e);
        }

    }

    return null;
}

From source file:org.pentaho.di.i18n.GlobalMessageUtil.java

@VisibleForTesting
static String calculateString(final String packageName, final Locale locale, final String key,
        final Object[] parameters, final Class<?> resourceClass, final String bundleName,
        final boolean fallbackOnRoot) throws MissingResourceException {
    try {//w ww.j a  v a  2  s  .  com
        ResourceBundle bundle = getBundle(locale, packageName + "." + bundleName, resourceClass,
                fallbackOnRoot);
        String unformattedString = bundle.getString(key);
        String string = MessageFormat.format(unformattedString, parameters);
        return string;
    } catch (IllegalArgumentException e) {
        final StringBuilder msg = new StringBuilder();
        msg.append("Format problem with key=[").append(key).append("], locale=[").append(locale)
                .append("], package=").append(packageName).append(" : ").append(e.toString());
        log.error(msg.toString());
        log.error(Const.getStackTracker(e));
        throw new MissingResourceException(msg.toString(), packageName, key);
    }
}

From source file:com.streamsets.datacollector.validation.ValidationUtil.java

@SuppressWarnings("unchecked")
private static boolean validateModel(UserConfigurable stageConf, Map<String, ConfigDefinition> definitionMap,
        Set<String> hideConfigs, ConfigDefinition confDef, Config conf, IssueCreator issueCreator,
        List<Issue> issues) {
    boolean preview = true;
    switch (confDef.getModel().getModelType()) {
    case VALUE_CHOOSER:
        if (!(conf.getValue() instanceof String || conf.getValue().getClass().isEnum())) {
            // stage configuration must be a model
            issues.add(issueCreator.create(confDef.getGroup(), confDef.getName(),
                    ValidationError.VALIDATION_0009, "String"));
            preview = false;//from   w  ww.  j  av  a 2  s .c o  m
        }
        break;
    case FIELD_SELECTOR_MULTI_VALUE:
        if (!(conf.getValue() instanceof List)) {
            // stage configuration must be a model
            issues.add(issueCreator.create(confDef.getGroup(), confDef.getName(),
                    ValidationError.VALIDATION_0009, "List"));
            preview = false;
        } else {
            //validate all the field names for proper syntax
            List<String> fieldPaths = (List<String>) conf.getValue();
            for (String fieldPath : fieldPaths) {
                try {
                    PathElement.parse(fieldPath, true);
                } catch (IllegalArgumentException e) {
                    issues.add(issueCreator.create(confDef.getGroup(), confDef.getName(),
                            ValidationError.VALIDATION_0033, e.toString()));
                    preview = false;
                    break;
                }
            }
        }
        break;
    case LIST_BEAN:
        if (conf.getValue() != null) {
            //this can be a single HashMap or an array of hashMap
            Map<String, ConfigDefinition> configDefinitionsMap = new HashMap<>();
            for (ConfigDefinition c : confDef.getModel().getConfigDefinitions()) {
                configDefinitionsMap.put(c.getName(), c);
            }
            if (conf.getValue() instanceof List) {
                //list of hash maps
                List<Map<String, Object>> maps = (List<Map<String, Object>>) conf.getValue();
                for (Map<String, Object> map : maps) {
                    preview &= validateComplexConfig(configDefinitionsMap, map, stageConf, definitionMap,
                            hideConfigs, issueCreator, issues);
                }
            } else if (conf.getValue() instanceof Map) {
                preview &= validateComplexConfig(configDefinitionsMap, (Map<String, Object>) conf.getValue(),
                        stageConf, definitionMap, hideConfigs, issueCreator, issues);
            }
        }
        break;
    case PREDICATE:
        if (!(conf.getValue() instanceof List)) {
            // stage configuration must be a model
            issues.add(issueCreator.create(confDef.getGroup(), confDef.getName(),
                    ValidationError.VALIDATION_0009, "List<Map>"));
            preview = false;
        } else {
            int count = 1;
            for (Object element : (List) conf.getValue()) {
                if (element instanceof Map) {
                    Map map = (Map) element;
                    if (!map.containsKey("outputLane")) {
                        issues.add(issueCreator.create(confDef.getGroup(), confDef.getName(),
                                ValidationError.VALIDATION_0020, count, "outputLane"));
                        preview = false;
                    } else {
                        if (map.get("outputLane") == null) {
                            issues.add(issueCreator.create(confDef.getGroup(), confDef.getName(),
                                    ValidationError.VALIDATION_0021, count, "outputLane"));
                            preview = false;
                        } else {
                            if (!(map.get("outputLane") instanceof String)) {
                                issues.add(issueCreator.create(confDef.getGroup(), confDef.getName(),
                                        ValidationError.VALIDATION_0022, count, "outputLane"));
                                preview = false;
                            } else if (((String) map.get("outputLane")).isEmpty()) {
                                issues.add(issueCreator.create(confDef.getGroup(), confDef.getName(),
                                        ValidationError.VALIDATION_0023, count, "outputLane"));
                                preview = false;
                            }
                        }
                    }
                    if (!map.containsKey("predicate")) {
                        issues.add(issueCreator.create(confDef.getGroup(), confDef.getName(),
                                ValidationError.VALIDATION_0020, count, "condition"));
                        preview = false;
                    } else {
                        if (map.get("predicate") == null) {
                            issues.add(issueCreator.create(confDef.getGroup(), confDef.getName(),
                                    ValidationError.VALIDATION_0021, count, "condition"));
                            preview = false;
                        } else {
                            if (!(map.get("predicate") instanceof String)) {
                                issues.add(issueCreator.create(confDef.getGroup(), confDef.getName(),
                                        ValidationError.VALIDATION_0022, count, "condition"));
                                preview = false;
                            } else if (((String) map.get("predicate")).isEmpty()) {
                                issues.add(issueCreator.create(confDef.getGroup(), confDef.getName(),
                                        ValidationError.VALIDATION_0023, count, "condition"));
                                preview = false;
                            }
                        }
                    }
                } else {
                    issues.add(issueCreator.create(confDef.getGroup(), confDef.getName(),
                            ValidationError.VALIDATION_0019, count));
                    preview = false;
                }
                count++;
            }
        }
        break;
    case FIELD_SELECTOR:
        // fall through
    case MULTI_VALUE_CHOOSER:
        break;
    default:
        throw new RuntimeException("Unknown model type: " + confDef.getModel().getModelType().name());
    }
    return preview;
}

From source file:android_network.hetnet.vpn_service.Util.java

public static boolean isEnabled(PackageInfo info, Context context) {
    int setting;/*  w ww . j  av a2s. c om*/
    try {
        PackageManager pm = context.getPackageManager();
        setting = pm.getApplicationEnabledSetting(info.packageName);
    } catch (IllegalArgumentException ex) {
        setting = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
        Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
    if (setting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)
        return info.applicationInfo.enabled;
    else
        return (setting == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
}

From source file:com.aron.framedemo.widget.PhotoViewPager.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    try {/*from   w w w . j  av a2 s  .c o m*/
        return super.onTouchEvent(ev);
    } catch (IllegalArgumentException ex) {
        KLog.e(ex.toString());
    }
    return false;
}