Example usage for java.lang RuntimeException getMessage

List of usage examples for java.lang RuntimeException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.google.visualization.datasource.DataSourceHelper.java

/**
 * Checks that the query is valid against the structure of the data table.
 * A query is invalid if:/* w w w .  j ava 2s  . c om*/
 * <ol>
 * <li> The query references column ids that don't exist in the data table.
 * <li> The query contains calculated columns operations (i.e., scalar function, aggregations)
 * that do not match the relevant columns type.
 * </ol>
 *
 * Note: does NOT validate the query itself, i.e. errors like "SELECT a, a" or
 * "SELECT a GROUP BY a" will not be caught. These kind of errors should be checked elsewhere
 * (preferably by the <code>Query.validate()</code> method).
 *
 * @param query The query to check for validity.
 * @param dataTable The data table against which to validate. Only the columns are used.
 *
 * @throws InvalidQueryException Thrown if the query is found to be invalid
 *     against the given data table.
 */
public static void validateQueryAgainstColumnStructure(Query query, DataTable dataTable)
        throws InvalidQueryException {
    // Check that all the simple columns exist in the table (including the
    // simple columns inside aggregation and scalar-function columns)
    Set<String> mentionedColumnIds = query.getAllColumnIds();
    for (String columnId : mentionedColumnIds) {
        if (!dataTable.containsColumn(columnId)) {
            String messageToLogAndUser = MessagesEnum.NO_COLUMN
                    .getMessageWithArgs(dataTable.getLocaleForUserMessages(), columnId);
            log.error(messageToLogAndUser);
            throw new InvalidQueryException(messageToLogAndUser);
        }
    }

    // Check that all aggregation columns are valid (i.e., the aggregation type
    // matches the columns type).
    Set<AggregationColumn> mentionedAggregations = query.getAllAggregations();
    for (AggregationColumn agg : mentionedAggregations) {
        try {
            agg.validateColumn(dataTable);
        } catch (RuntimeException e) {
            log.error("A runtime exception has occured", e);
            throw new InvalidQueryException(e.getMessage());
        }
    }

    // Check that all scalar function columns are valid. (i.e., the scalar
    // function matches the columns types).
    Set<ScalarFunctionColumn> mentionedScalarFunctionColumns = query.getAllScalarFunctionsColumns();
    for (ScalarFunctionColumn col : mentionedScalarFunctionColumns) {
        col.validateColumn(dataTable);
    }
}

From source file:org.dspace.servicemanager.DSpaceServiceManager.java

/**
 * Adds configuration settings into services if possible.
 * Skips any that are invalid.//from   ww w . jav a  2  s  .  c  om
 * 
 * @param serviceName the name of the service
 * @param service the service object
 * @param serviceNameConfigs all known service configuration settings (from the DS config service impl)
 */
public static void configureService(String serviceName, Object service,
        Map<String, Map<String, ServiceConfig>> serviceNameConfigs) {
    // stuff the config settings into the bean if there are any
    if (serviceNameConfigs.containsKey(serviceName)) {
        BeanWrapper beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(service);

        Map<String, ServiceConfig> configs = serviceNameConfigs.get(serviceName);
        for (ServiceConfig config : configs.values()) {
            try {
                beanWrapper.setPropertyValue(config.getParamName(), config.getValue());

                log.info("Set param (" + config.getParamName() + ") on service bean (" + serviceName + ") to: "
                        + config.getValue());
            } catch (RuntimeException e) {
                log.error("Unable to set param (" + config.getParamName() + ") on service bean (" + serviceName
                        + "): " + e.getMessage(), e);
            }
        }
    }
}

From source file:edu.buffalo.cse.pigout.parser.QueryParserDriver.java

static Tree parse(CommonTokenStream tokens) throws ParserException {
    QueryParser parser = QueryParserUtils.createParser(tokens);

    QueryParser.query_return result = null;
    try {/*w w  w. j  a v  a 2 s. c  o m*/
        result = parser.query();
    } catch (RecognitionException e) {
        String msg = parser.getErrorHeader(e) + " " + parser.getErrorMessage(e, parser.getTokenNames());
        throw new ParserException(msg);
    } catch (RuntimeException ex) {
        throw new ParserException(ex.getMessage());
    }

    Tree ast = (Tree) result.getTree();
    checkError(parser);

    return ast;
}

From source file:io.cloudslang.lang.tools.build.SlangBuildMain.java

private static void logErrors(List<RuntimeException> exceptions, String projectPath,
        final LoggingService loggingService) {
    logErrorsPrefix(loggingService);/*from   w  w  w .j  av a  2  s.  c  om*/
    for (RuntimeException runtimeException : exceptions) {
        loggingService.logEvent(Level.ERROR, "Exception: " + runtimeException.getMessage());
    }
    logErrorsSuffix(projectPath, loggingService);
    loggingService.waitForAllLogTasksToFinish();
    System.exit(1);
}

From source file:com.shieldsbetter.sbomg.Cli.java

private static ProjectDescriptor parseProjectDescriptor(File location, InputStream d)
        throws OperationException {
    String locationPath = location.getPath();
    ProjectDescriptor result;//from  w  w w  .  ja  v a 2s .  co m
    Object rawDescriptor;
    try {
        rawDescriptor = new Yaml().load(d);
    } catch (RuntimeException re) {
        throw new OperationException(
                "Couldn't parse project descriptor " + locationPath + ": \n" + re.getMessage());
    }

    if (!(rawDescriptor instanceof Map)) {
        throw new OperationException("Project descriptor " + locationPath + " must be a YAML map.");
    }
    Map rawDescriptorMap = (Map) rawDescriptor;

    Object rawSrcDirs = rawDescriptorMap.remove("source directories");
    if (rawSrcDirs == null) {
        throw new OperationException("Project descriptor " + locationPath
                + " must contain 'source directories' key.  Keys are case " + "sensitive.");
    }

    List rawSrcDirsList;
    if (rawSrcDirs instanceof List) {
        rawSrcDirsList = (List) rawSrcDirs;
    } else if (rawSrcDirs instanceof String) {
        rawSrcDirsList = ImmutableList.of(rawSrcDirs);
    } else {
        throw new OperationException("In project descriptor " + location
                + ", 'source directories' key must map to a string or a " + "list of strings.");
    }

    List<File> srcDirs = new LinkedList<>();
    for (Object rawSrcDir : rawSrcDirsList) {
        if (!(rawSrcDir instanceof String)) {
            throw new OperationException("In project descriptor " + location
                    + ", 'source directories' contains a non-string " + "element: " + rawSrcDir);
        }

        srcDirs.add(new File((String) rawSrcDir));
    }

    Object rawTargetDir = rawDescriptorMap.remove("target directory");
    if (rawTargetDir == null) {
        throw new OperationException("Project descriptor " + location
                + " must contain 'target directory' key.  Keys are case " + "sensitive.");
    }

    if (!(rawTargetDir instanceof String)) {
        throw new OperationException("In project descriptor " + location
                + ", 'target directory' maps to a non-string element: " + rawTargetDir);
    }

    File targetDir = new File((String) rawTargetDir);
    return new ProjectDescriptor(location.getParentFile(), srcDirs, targetDir);
}

From source file:com.espertech.esper.core.EPServicesContextFactoryDefault.java

protected static ExceptionHandlingService initExceptionHandling(String engineURI,
        ConfigurationEngineDefaults.ExceptionHandling exceptionHandling,
        ConfigurationEngineDefaults.ConditionHandling conditionHandling) throws ConfigurationException {
    List<ExceptionHandler> exceptionHandlers;
    if (exceptionHandling.getHandlerFactories() == null || exceptionHandling.getHandlerFactories().isEmpty()) {
        exceptionHandlers = Collections.emptyList();
    } else {//from w w w  . ja  v a  2s  .  c om
        exceptionHandlers = new ArrayList<ExceptionHandler>();
        ExceptionHandlerFactoryContext context = new ExceptionHandlerFactoryContext(engineURI);
        for (String className : exceptionHandling.getHandlerFactories()) {
            try {
                ExceptionHandlerFactory factory = (ExceptionHandlerFactory) JavaClassHelper
                        .instantiate(ExceptionHandlerFactory.class, className);
                ExceptionHandler handler = factory.getHandler(context);
                if (handler == null) {
                    log.warn("Exception handler factory '" + className
                            + "' returned a null handler, skipping factory");
                    continue;
                }
                exceptionHandlers.add(handler);
            } catch (RuntimeException ex) {
                throw new ConfigurationException(
                        "Exception initializing exception handler from exception handler factory '" + className
                                + "': " + ex.getMessage(),
                        ex);
            }
        }
    }

    List<ConditionHandler> conditionHandlers;
    if (conditionHandling.getHandlerFactories() == null || conditionHandling.getHandlerFactories().isEmpty()) {
        conditionHandlers = Collections.emptyList();
    } else {
        conditionHandlers = new ArrayList<ConditionHandler>();
        ConditionHandlerFactoryContext context = new ConditionHandlerFactoryContext(engineURI);
        for (String className : conditionHandling.getHandlerFactories()) {
            try {
                ConditionHandlerFactory factory = (ConditionHandlerFactory) JavaClassHelper
                        .instantiate(ConditionHandlerFactory.class, className);
                ConditionHandler handler = factory.getHandler(context);
                if (handler == null) {
                    log.warn("Condition handler factory '" + className
                            + "' returned a null handler, skipping factory");
                    continue;
                }
                conditionHandlers.add(handler);
            } catch (RuntimeException ex) {
                throw new ConfigurationException(
                        "Exception initializing exception handler from exception handler factory '" + className
                                + "': " + ex.getMessage(),
                        ex);
            }
        }
    }
    return new ExceptionHandlingService(engineURI, exceptionHandlers, conditionHandlers);
}

From source file:org.eclipse.cft.server.core.internal.CloudErrorUtil.java

/**
 * If the error is a server communication error, it wraps it in a
 * {@link CoreException} with user-friendly message. If the server
 * communciation error is due to {@link SSLPeerUnverifiedException}, the
 * latter is set as the cause for the wrapped CoreException. Otherwise,
 * returns the error as the cause in a CoreException. Always returns a
 * {@link CoreException}./*  w  w w .  j a v a  2 s .  c om*/
 * @param e
 * @return CoreException wrapper if communication error with server, or
 * otherwise return CoreException with original error as cause. Never null.
 * 
 */
public static CoreException checkServerCommunicationError(RuntimeException e) {
    if (e != null && e.getCause() instanceof IOException) {
        // Set the cause for SSL
        if ((e.getCause() instanceof SSLPeerUnverifiedException)) {
            return toCoreException(e.getCause());
        } else {
            // Log other IO errors.
            String errorMessage = NLS.bind(Messages.ERROR_UNABLE_TO_COMMUNICATE_SERVER, e.getMessage());
            CloudFoundryPlugin.logError(errorMessage, e);
            return new CoreException(new Status(IStatus.ERROR, CloudFoundryPlugin.PLUGIN_ID, errorMessage));
        }
    } else {
        return checkRestException(e);
    }
}

From source file:com.nextep.datadesigner.sqlgen.impl.SQLGenerator.java

/**
 * Integrates a collection of generation results into a single generation
 * result. Dependencies may be resolved depending on the resolveDependency
 * flag. Null generation results will be filtered.
 * /*from   w ww.j a  va2  s . co  m*/
 * @param name
 *            name of the resulting generation result
 * @param generations
 *            a collection of all generation results to integrate
 * @param resolveDependencies
 *            a flag indicating if the integration should resolve
 *            dependencies. It consists in ordering the results depending on
 *            their dependencies (i.e. to ensure tables are created before
 *            indexes, etc.)
 * @return a single generation result integrating the collection of results
 */
public static IGenerationResult integrateAll(String name, List<IGenerationResult> generations,
        boolean resolveDependencies) {
    // Initializing generation result
    IGenerationResult generation = new GenerationResult(name);
    // Removing null entries
    List<IGenerationResult> nonNullResults = new ArrayList<IGenerationResult>();
    for (IGenerationResult r : generations) {
        if (r != null) {
            nonNullResults.add(r);
        }
    }
    // Resolving by ordering generations (see the GenerationResult
    // comparator implementation)
    List<IGenerationResult> resolvedResults = new ArrayList<IGenerationResult>();
    if (resolveDependencies) {
        // Try / catch safe blocks added for DES-925 problems
        try {
            Collections.sort(nonNullResults, NameComparator.getInstance());
        } catch (RuntimeException e) {
            LOGGER.warn("Unable to sort generation results by name: " + e.getMessage(), e); //$NON-NLS-1$
        }
        try {
            Collections.sort(nonNullResults);
        } catch (RuntimeException e) {
            LOGGER.warn("Unable to sort generation results by natural comparison: " //$NON-NLS-1$
                    + e.getMessage(), e);
        }
        // Since comparator of IGenerationResult is not transitive
        // the sort might not resolve all dependencies
        // Hashing results by db ref
        Map<DatabaseReference, IGenerationResult> refMap = new HashMap<DatabaseReference, IGenerationResult>();
        for (IGenerationResult result : nonNullResults) {
            for (DatabaseReference generatedRef : result.getGeneratedReferences()) {
                refMap.put(generatedRef, result);
            }
        }
        // Resolving
        for (IGenerationResult result : nonNullResults) {
            if (!resolvedResults.contains(result)) {
                processPreconditions(result, resolvedResults, refMap, new ArrayList<IGenerationResult>());
            }
        }
    } else {
        resolvedResults = nonNullResults;
    }
    // Integrating children generations
    for (IGenerationResult r : resolvedResults) {
        generation.integrate(r);
    }
    return generation;
}

From source file:de.xirp.chart.ChartManager.java

/**
 * Returns a list of scatter charts. The charts are generated from
 * the given record->interval map and key array. One chart is
 * generated for each {@link de.xirp.db.Record} in
 * the map. The records are evaluated using the mapped
 * {@link de.xirp.ui.widgets.dialogs.ChartConfigDialog.Interval}.
 * /*from  www  .  j  av a2  s  .  c o  m*/
 * @param recordIntervalMap
 *            The records with the data and the intervals.
 * @param keys
 *            The keys to use.
 * @return A list of scatter charts.
 * @see org.jfree.chart.JFreeChart
 * @see de.xirp.db.Record
 * @see de.xirp.ui.widgets.dialogs.ChartConfigDialog.Interval
 */
public static List<JFreeChart> createScatterChart(Map<Record, Interval> recordIntervalMap, String[] keys) {
    List<JFreeChart> charts = new ArrayList<JFreeChart>();
    Interval i;
    for (Record record : recordIntervalMap.keySet()) {
        i = recordIntervalMap.get(record);
        try {
            charts.add(createScatterChart(record, keys, i.start.getTime(), i.stop.getTime(), false));
        } catch (RuntimeException e) {
            logClass.error("Error: " + e.getMessage() //$NON-NLS-1$
                    + Constants.LINE_SEPARATOR, e);
        }
    }
    return charts;
}

From source file:de.xirp.chart.ChartManager.java

/**
 * Returns a list of time series charts. They are generated from
 * the given <code>Map&lt;Record, Interval&gt;</code> and the
 * key array. A chart is generated for each
 * {@link de.xirp.db.Record} in the map using the
 * associated// w  ww. j  a  v a2 s  .  c  o m
 * {@link de.xirp.ui.widgets.dialogs.ChartConfigDialog.Interval}
 * and the keys array.
 * 
 * @param recordIntervalMap
 *            Records mapped to the interval to use.
 * @param keys
 *            The keys to use.
 * @return A <code>List&lt;JFreeChart&gt;</code> with time
 *         series charts.
 */
public static List<JFreeChart> createTimeSeriesChart(Map<Record, Interval> recordIntervalMap, String[] keys) {

    List<JFreeChart> charts = new ArrayList<JFreeChart>();
    Interval i;
    for (Record record : recordIntervalMap.keySet()) {
        i = recordIntervalMap.get(record);
        try {
            charts.add(createTimeSeriesChart(record, keys, i.start.getTime(), i.stop.getTime(), false));
        } catch (RuntimeException e) {
            logClass.error("Error: " + e.getMessage() //$NON-NLS-1$
                    + Constants.LINE_SEPARATOR, e);
        }
    }
    return charts;
}