Example usage for java.lang IllegalArgumentException getClass

List of usage examples for java.lang IllegalArgumentException getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.mijecu25.sqlplus.SQLPlus.java

public static void main(String[] args) throws IOException {
    // Create and load the properties from the application properties file
    Properties properties = new Properties();
    properties.load(SQLPlus.class.getClassLoader().getResourceAsStream(SQLPlus.APPLICATION_PROPERTIES_FILE));

    SQLPlus.logger.info("Initializing " + SQLPlus.PROGRAM_NAME + " version "
            + properties.getProperty(SQLPlus.APPLICATION_PROPERTIES_FILE_VERSION));

    // Check if the user is using a valid console (i.e. not from Eclipse)
    if (System.console() == null) {
        // The Console object for the JVM could not be found. Alert the user 
        SQLPlus.logger.fatal(Messages.FATAL + "A JVM Console object was not found. Try running "
                + SQLPlus.PROGRAM_NAME + "from the command line");
        System.out.println(/*from   w  ww  .j  a v  a  2s  . c o  m*/
                Messages.FATAL + SQLPlus.PROGRAM_NAME + " was not able to find your JVM's Console object. "
                        + "Try running " + SQLPlus.PROGRAM_NAME + " from the command line.");

        SQLPlus.exitSQLPlus();

        SQLPlus.logger.fatal(Messages.FATAL + Messages.QUIT_PROGRAM_ERROR(PROGRAM_NAME));
        return;
    }

    // UI intro
    System.out.println("Welcome to " + SQLPlus.PROGRAM_NAME
            + "! This program has a DSL to add alerts to various SQL DML events.");
    System.out.println("Be sure to use " + SQLPlus.PROGRAM_NAME + " from the command line.");
    System.out.println();

    // Get the version
    System.out.println("Version: " + properties.getProperty(SQLPlus.APPLICATION_PROPERTIES_FILE_VERSION));
    System.out.println();

    // Read the license file
    BufferedReader bufferedReader;
    bufferedReader = new BufferedReader(new FileReader(SQLPlus.LICENSE_FILE));

    // Read a line
    String line = bufferedReader.readLine();

    // While the line is not null
    while (line != null) {
        System.out.println(line);

        // Read a new lines
        line = bufferedReader.readLine();
    }

    // Close the buffer
    bufferedReader.close();
    System.out.println();

    // Create the jline console that allows us to remember commands, use arrow keys, and catch interruptions
    // from the user
    SQLPlus.console = new ConsoleReader();
    SQLPlus.console.setHandleUserInterrupt(true);

    try {
        // Get credentials from the user
        SQLPlus.logger.info("Create SQLPlusConnection");
        SQLPlus.createSQLPlusConnection();
    } catch (NullPointerException | SQLException | IllegalArgumentException e) {
        // NPE: This exception can occur if the user is running the program where the JVM Console
        // object cannot be found.
        // SQLE: TODO should I add here the error code?
        // This exception can occur when trying to establish a connection
        // IAE: This exception can occur when trying to establish a connection
        SQLPlus.logger
                .fatal(Messages.FATAL + Messages.FATAL_EXIT(SQLPlus.PROGRAM_NAME, e.getClass().getName()));
        System.out.println(Messages.FATAL + Messages.FATAL_EXCEPTION_ACTION(e.getClass().getSimpleName()) + " "
                + Messages.CHECK_LOG_FILES);
        SQLPlus.exitSQLPlus();

        SQLPlus.logger.fatal(Messages.FATAL + Messages.QUIT_PROGRAM_ERROR(SQLPlus.PROGRAM_NAME));
        return;
    } catch (UserInterruptException uie) {
        SQLPlus.logger.warn(Messages.WARNING + "The user typed an interrupt instruction.");
        SQLPlus.exitSQLPlus();

        return;
    }

    System.out.println("Connection established! Commands end with " + SQLPlus.END_OF_COMMAND);
    System.out.println("Type " + SQLPlus.EXIT + " or " + SQLPlus.QUIT + " to exit the application ");

    try {
        // Execute the input scanner
        while (true) {
            // Get a line from the user until the hit enter (carriage return, line feed/ new line).
            System.out.print(SQLPlus.PROMPT);
            try {
                line = SQLPlus.console.readLine().trim();
            } catch (NullPointerException npe) {
                // TODO test this behavior
                // If this exception is catch, it is very likely that the user entered the end of line command.
                // This means that the program should quit.
                SQLPlus.logger.warn(Messages.WARNING + "The input from the user is null. It is very likely that"
                        + "the user entered the end of line command and they want to quit.");
                SQLPlus.exitSQLPlus();

                return;
            }

            // If the user did not enter anything
            if (line.isEmpty()) {
                // Continue to the next iteration
                continue;
            }

            if (line.equals(".")) {
                line = "use courses;";
            }

            if (line.equals("-")) {
                line = "select created_at from classes;";
            }

            if (line.equals("--")) {
                line = "select name, year from classes;";
            }

            if (line.equals("*")) {
                line = "select * from classes;";
            }

            if (line.equals("x")) {
                line = "select name from classes, classes;";
            }

            if (line.equals("e")) {
                line = "select * feom classes;";
            }

            // Logic to quit
            if (line.equals(SQLPlus.QUIT) || line.equals(SQLPlus.EXIT)) {
                SQLPlus.logger.info("The user wants to quit " + SQLPlus.PROGRAM_NAME);
                SQLPlus.exitSQLPlus();
                break;
            }

            // Use a StringBuilder since jline works weird when it has read a line. The issue we were having was with the
            // end of command logic. jline does not keep the input from the user in the variable that was stored in. Each
            // time jline reads a new line, the variable is empty
            StringBuilder query = new StringBuilder();
            query.append(line);

            // While the user does not finish the command with the SQLPlus.END_OF_COMMAND
            while (query.charAt(query.length() - 1) != SQLPlus.END_OF_COMMAND) {
                // Print the wait for command prompt and get the next line for the user
                System.out.print(SQLPlus.WAIT_FOR_END_OF_COMMAND);
                query.append(" ");
                line = StringUtils.stripEnd(SQLPlus.console.readLine(), null);
                query.append(line);
            }

            SQLPlus.logger.info("Raw input from the user: " + query);

            try {
                Statement statement;

                try {
                    // Execute the antlr code to parse the user input
                    SQLPlus.logger.info("Will parse the user input to determine what to execute");
                    ANTLRStringStream input = new ANTLRStringStream(query.toString());
                    SQLPlusLex lexer = new SQLPlusLex(input);
                    CommonTokenStream tokens = new CommonTokenStream(lexer);
                    SQLPlusParser parser = new SQLPlusParser(tokens);

                    statement = parser.sqlplus();
                } catch (RecognitionException re) {
                    // TODO move this to somehwere else
                    //                        String message = Messages.WARNING + "You have an error in your SQL syntax. Check the manual"
                    //                                + " that corresponds to your " + SQLPlus.sqlPlusConnection.getCurrentDatabase()
                    //                                + " server or " + SQLPlus.PROGRAM_NAME + " for the correct syntax";
                    //                        SQLPlus.logger.warn(message);
                    //                        System.out.println(message);
                    statement = new StatementDefault();
                }

                statement.setStatement(query.toString());
                SQLPlus.sqlPlusConnection.execute(statement);
            } catch (UnsupportedOperationException uoe) {
                // This exception can occur when the user entered a command allowed by the parsers, but not currently
                // supported by SQLPlus. This can occur because the parser is written in such a way that supports
                // the addition of features.
                SQLPlus.logger.warn(Messages.WARNING + uoe);
                System.out.println(
                        Messages.WARNING + Messages.FATAL_EXCEPTION_ACTION(uoe.getClass().getSimpleName()) + " "
                                + Messages.CHECK_LOG_FILES);
                SQLPlus.logger.warn(Messages.WARNING + "The previous command is not currently supported.");
            }

        }
    } catch (IllegalArgumentException iae) {
        // This exception can occur when a command is executed but it had illegal arguments. Most likely
        // it is a programmer's error and should be addressed by the developer.
        SQLPlus.logger
                .fatal(Messages.FATAL + Messages.FATAL_EXIT(SQLPlus.PROGRAM_NAME, iae.getClass().getName()));
        SQLPlus.exitSQLPlus();

        SQLPlus.logger.fatal(Messages.FATAL + Messages.QUIT_PROGRAM_ERROR(SQLPlus.PROGRAM_NAME));
    } catch (UserInterruptException uie) {
        SQLPlus.logger.warn(Messages.WARNING + "The user typed an interrupt instruction.");
        SQLPlus.exitSQLPlus();
    }
}

From source file:org.kepler.Kepler.java

/** Run the appropriate application based on command line arguments. */
public static int runApplication() {

    try {/*from  w  w  w .  j  a  v a  2 s .c  o m*/
        // see if we're running the gui editor
        if (_action == Action.Kepler) {
            addActorModule("org/kepler/ActorModuleDefault");
            initialize();
            _applicationArgsList.addFirst("-kepler");
            String[] loadArgs = _applicationArgsList.toArray(new String[0]);
            if (_showSplash) {
                SplashWindow.invokeMain("ptolemy.vergil.VergilApplication", loadArgs);
                SplashWindow.disposeSplash();
            } else {
                VergilApplication.main(loadArgs);
            }

            // check for patches now that the UI has started.
            PatchChecker.check(false);

        } else if (_action == Action.Vergil) {
            addActorModule("org/kepler/ActorModuleDefault");
            String[] loadArgs = _applicationArgsList.toArray(new String[0]);
            VergilApplication.main(loadArgs);
        } else if (_action == Action.RunWf || _action == Action.RunKAR) {
            String className = null;

            // if we are running a workflow from the cmd line and have
            // the gui enabled, the program does not quit until the user
            // enters control-c.
            if (_runWithGui) {
                _mustManuallyQuit = true;
            }
            addActorModule("org/kepler/ActorModuleDefault");
            if (_runWithGui && _runWithCache) {
                if (_action == Action.RunKAR) {
                    if (_applicationArgsList.getLast().endsWith(".xml")) {
                        throw new IllegalArgumentException(
                                "ERROR: -runkar " + "can only be used to run kar file, not xml file."
                                        + "to run xml file, please use -runwf option");
                    }
                    className = "org.kepler.KeplerConfigurationApplication";
                    _applicationArgsList.addFirst("-run");
                    _applicationArgsList.addFirst("ptolemy/configs/kepler/ConfigGUIAndCache.xml");
                } else { // _action == Action.RunWf
                    if (_applicationArgsList.getLast().endsWith(".kar")) {
                        throw new IllegalArgumentException(
                                "ERROR: -runwf " + "can only be used to run xml file, not kar file."
                                        + " To run kar file, please use -runkar option");
                    }
                    className = "ptolemy.actor.gui.PtExecuteApplication";
                    _applicationArgsList.addFirst("ptolemy/configs/kepler/ConfigGUIAndCache.xml");
                    _applicationArgsList.addFirst("-conf");
                }
            } else if (_runWithGui && !_runWithCache) {
                if (_applicationArgsList.getLast().endsWith(".kar")) {
                    throw new IllegalArgumentException(
                            "ERROR: -runkar " + "cannot be used with -nocache option."
                                    + " Please remove nocache option and try again.");
                }
                className = "ptolemy.actor.gui.PtExecuteApplication";
                _applicationArgsList.addFirst("ptolemy/configs/kepler/ConfigGUINoCache.xml");
                _applicationArgsList.addFirst("-conf");
            } else if (!_runWithGui && _runWithCache) {
                String spec;
                if (_displayRedirectOutputPath != null) {
                    //add display redirection filter
                    BackwardCompatibility.addFilter(
                            new au.edu.jcu.kepler.hydrant.DisplayRedirectFilter(_displayRedirectOutputPath));
                    addActorModule("org/kepler/ActorModuleBatch");
                    spec = "ptolemy/configs/kepler/ConfigRedirectGUIWithCache.xml";
                } else {
                    spec = "ptolemy/configs/kepler/ConfigNoGUIWithCache.xml";
                }
                className = "org.kepler.KeplerConfigurationApplication";
                _applicationArgsList.addFirst("-runThenExit");
                _applicationArgsList.addFirst(spec);
                // ConfigurationApplication.readConfiguration(ConfigurationApplication.specToURL(spec));
            } else { // if(!gui && !cache)
                if (_applicationArgsList.getLast().endsWith(".kar")) {
                    throw new IllegalArgumentException(
                            "ERROR: -runkar " + "cannot be used with -nocache option."
                                    + " Please remove '-nocache' option and try again.");
                }
                String spec;
                if (_displayRedirectOutputPath != null)
                //enter into display redirection mode
                {
                    BackwardCompatibility.addFilter(
                            new au.edu.jcu.kepler.hydrant.DisplayRedirectFilter(_displayRedirectOutputPath));
                    addActorModule("org/kepler/ActorModuleBatch");
                    //                        DisplayRediectClassChanges.classChanges();
                    //                        BackwardCompatibility.addFilter(new DisplayRedirectFilter(outputPath));                      
                    spec = "ptolemy/configs/kepler/ConfigRedirectGUINoCache.xml";

                } else {
                    spec = "ptolemy/configs/kepler/ConfigNoGUINoCache.xml";
                }
                className = "org.kepler.KeplerConfigurationApplication";
                _applicationArgsList.addFirst("-runThenExit");
                _applicationArgsList.addFirst(spec);
                //                  else{
                //                     className = "ptolemy.moml.MoMLCommandLineApplication";
                //                  }
            }

            if (className != null) {
                // initialize and run the class.
                String[] loadArgs = _applicationArgsList.toArray(new String[0]);
                load(className, loadArgs);
            }
        } else if (_action == Action.CreateActorXML) {
            String[] loadArgs = _applicationArgsList.toArray(new String[0]);
            load("org.kepler.loader.util.UpdateActorTreeFiles", "buildXMLs", loadArgs);
        } else if (_action == Action.UpdateActorDocs) {
            String[] loadArgs = _applicationArgsList.toArray(new String[0]);
            load("org.kepler.loader.util.UpdateActorTreeFiles", "updateKarXMLDocsForFile", loadArgs);
        } else if (_action == Action.HSQLStart) {
            System.out.println("going to start hsql servers.");
            _runHSQLServers(true);
        } else if (_action == Action.HSQLStop) {
            System.out.println("going to stop hsql servers.");
            _runHSQLServers(false);
        }
    } catch (IllegalArgumentException e) {
        System.out.print(e.getMessage());
        return 1;
    } catch (Exception e) {
        System.out.println(e.getClass() + ": " + e.getMessage());
        e.printStackTrace();
        return 1;
    }

    if (_exitAfterRun) {
        System.exit(0);
    }
    return 0;
}

From source file:throwsaop.SimpleThrowsAdvice.java

public void afterThrowing(Method m, Object[] args, Object target, IllegalArgumentException ex)
        throws Throwable {
    System.out.println("***");
    System.out.println("IllegalArgumentException capture");
    System.out.println("Caught: " + ex.getClass().getName());
    System.out.println("Method: " + m.getName());
    System.out.println("***");
    System.out.println("");
}

From source file:org.cloudifysource.dsl.ApplicationValidationTest.java

/*******
 * Tests the validation of an application without a name using DSL parsing
 * of a groovy file.//from w  w w.  j a  v  a  2  s  .  c  o m
 * <p>
 * Should throw <code>DSLValidationException</code>.
 */
@Test
public void testEmptyNameGroovyFileValidation() {
    final File applicationFile = new File(APPLICATION_WITH_EMPTY_NAME_GROOVY);
    try {
        ServiceReader.getApplicationFromFile(applicationFile).getApplication();
        Assert.fail("Application name is empty, IllegalArgumentException expected.");
    } catch (final IllegalArgumentException e) {
        // OK - the invalid application name caused the exception
    } catch (final Exception e) {
        Assert.fail("Application name is empty, IllegalArgumentException expected, instead " + e.getClass()
                + " was thrown.");
    }

}

From source file:org.cloudifysource.dsl.ApplicationValidationTest.java

/*******
 * Tests the validation of an application with an empty name using DSL
 * parsing of a groovy file./*from  w w  w . j a  va 2s .co  m*/
 * <p>
 * Should throw <code>DSLValidationException</code>.
 */
@Test
public void testNameNotExistGroovyFileValidation() {
    final File applicationFile = new File(APPLICATION_WITHOUT_NAME_GROOVY);
    try {
        ServiceReader.getApplicationFromFile(applicationFile).getApplication();
        Assert.fail("Application name is missing, IllegalArgumentException expected.");
    } catch (final IllegalArgumentException e) {
        // OK - the invalid application name caused the exception
    } catch (final Exception e) {
        Assert.fail("Application name is missing, IllegalArgumentException expected, instead " + e.getClass()
                + " was thrown.");
        e.printStackTrace();
    }
}

From source file:com.ecoplayer.beta.MusicService.java

private boolean playSong(Song song) {
    resetSongPlayingRef();/*  ww  w .  j ava 2s  .  c  om*/
    if (song != null) {
        if (isMediaPlayerInit) {
            mMediaPlayer.reset();
            try {
                mMediaPlayer.setDataSource(getApplicationContext(), getUriFromSong(song));
                // prepare async to not block main thread
                mMediaPlayer.prepareAsync();
                songPlaying = song;
                // Set the flag in the song to playing
                songPlaying.setPlaying(true);
                return true;
            } catch (IllegalArgumentException e) {
                Log.e(e.getClass().getName(), e.getMessage(), e);
            } catch (SecurityException e) {
                Log.e(e.getClass().getName(), e.getMessage(), e);
            } catch (IllegalStateException e) {
                Log.e(e.getClass().getName(), e.getMessage(), e);
            } catch (IOException e) {
                Log.e(e.getClass().getName(), e.getMessage(), e);
            }
        }
    } else {
        Log.e(getClass().getName(), "Error retrieving next song from queue, song is null");
    }
    return false;
}

From source file:org.cloudifysource.dsl.ApplicationValidationTest.java

/*******
 * Tests the validation of an application with an invalid name using DSL parsing of a groovy file.
 * <p>/*from  ww  w. ja  va 2  s .  c  o m*/
 * Should throw <code>DSLValidationException</code>.
 */
@Test
public void testInvalidNameGroovyFileValidation() {
    final File applicationFile = new File(APPLICATION_WITH_INVALID_NAME_GROOVY);
    try {
        ServiceReader.getApplicationFromFile(applicationFile).getApplication();
        Assert.fail(
                "Application name is invalid: " + INVALID_APP_NAME + ". IllegalArgumentException expected.");
    } catch (final IllegalArgumentException e) {
        // OK - the invalid application name caused the exception
    } catch (final Exception e) {
        Assert.fail("Application name is invalid: " + INVALID_APP_NAME + ". IllegalArgumentException expected, "
                + "but " + e.getClass() + " was thrown instead.");
        e.printStackTrace();
    }
}

From source file:com.jaspersoft.jasperserver.rest.services.RESTPermission.java

@Override
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServiceException {
    try {//from   ww w . j a va 2s .  co m
        JAXBList<ObjectPermission> perm = (JAXBList<ObjectPermission>) restUtils.unmarshal(req.getInputStream(),
                JAXBList.class, ObjectPermissionImpl.class, UserImpl.class, RoleImpl.class);
        for (int i = 0; i < perm.size(); i++) {
            if (isValidObjectPermission(perm.get(i)) && canUpdateObjectPermissions(perm.get(i)))
                try {
                    permissionsService.putPermission(perm.get(i));
                } catch (IllegalArgumentException e) {
                    throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
                } catch (RemoteException e) {
                    throw new ServiceException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                            e.getClass().getName() + (e.getMessage() != null ? ": " + e.getMessage() : ""));
                }
            else {
                if (perm.get(i).getPermissionRecipient() instanceof User) {
                    throw new AccessDeniedException("could not set permissions for: "
                            + ((User) perm.get(i).getPermissionRecipient()).getUsername());
                } else if (perm.get(i).getPermissionRecipient() instanceof Role) {
                    throw new AccessDeniedException("could not set permissions for: "
                            + ((Role) perm.get(i).getPermissionRecipient()).getRoleName());
                } else {
                    throw new AccessDeniedException(
                            "could not set permissions for: " + (perm.get(i).getPermissionRecipient() != null
                                    ? perm.get(i).getPermissionRecipient().toString()
                                    : "null"));
                }
            }
        }
        if (log.isDebugEnabled()) {
            log.debug("finished PUT permissions " + perm.size() + " permissions were added");
        }
        restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, "");
    } catch (AxisFault axisFault) {
        throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST,
                "please check the request job descriptor");
    } catch (IOException e) {
        throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST,
                "please check the request job descriptor");
    } catch (JAXBException e) {
        throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST,
                "please check the request job descriptor");
    }
}

From source file:org.cloudifysource.dsl.ServiceValidationTest.java

@Test
public void testApplicationMissingServiceIcon() {
    final File applicationFile = new File(APPLICATION_MISSING_SERVICE_ICON_PATH);
    try {/*ww  w . jav a 2s.  c om*/
        ServiceReader.getApplicationFromFile(applicationFile).getApplication();
        Assert.fail("Application has a service without an icon, IllegalArgumentException expected.");
    } catch (final IllegalArgumentException e) {
        // OK - the invalid application name caused the exception
    } catch (final Exception e) {
        Assert.fail("Application has a service without an icon, IllegalArgumentException expected, instead "
                + e.getClass() + " was thrown.");
    }
}

From source file:jp.terasoluna.fw.validation.FieldChecksTest11.java

/**
 * testValidateMultiField02() <br>
 * <br>/*w  w w. ja  v a2s .c  o m*/
 * () <br>
 * C, F, G, I <br>
 * <br>
 * () bean:""<br>
 * () va:ValidatorActionn?<br>
 * () field:???Field?<br>
 * <br>
 * varmultiFieldValidator=null<br>
 * () errors:MockValidationErrors?<br>
 * <br>
 * () errors:errorMessage?null??????<br>
 * () :IllegalArgumentException<br>
 *  "var value[multiFieldValidator] is required."<br>
 * () :ERROR<br>
 *  "var value[multiFieldValidator] is required."<br>
 * <br>
 * field??var-namemultiFieldValidator??var-value?null???? ???IllegalArgumentException??????<br>
 * <br>
 * bean????????????? <br>
 * @throws Exception ?????
 */
@Test
public void testValidateMultiField02() throws Exception {
    // ??
    Object bean = "";
    ValidatorAction va = new ValidatorAction();
    Field field = new Field();
    Var var = new Var("multiFieldValidator", null, null);
    field.addVar(var);
    FieldChecks_ValidationErrorsImpl03 errors = new FieldChecks_ValidationErrorsImpl03();

    // 
    FieldChecks fieldChecks = new FieldChecks();
    try {
        fieldChecks.validateMultiField(bean, va, field, errors);
        fail("IllegalArgumentException??????");
    } catch (IllegalArgumentException e) {
        // 
        assertNull(errors.errorMessage);
        assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName());
        assertEquals("var value[multiFieldValidator] is required.", e.getMessage());
        assertThat(logger.getLoggingEvents(), is(asList(error("var value[multiFieldValidator] is required."))));
    }
}