Example usage for java.lang IllegalArgumentException getCause

List of usage examples for java.lang IllegalArgumentException getCause

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.sakaiproject.genericdao.springjdbc.CrazyGenericDaoTest.java

/**
 * Test method for {@link org.sakaiproject.genericdao.hibernate.HibernateCompleteGenericDao#deleteMixedSet(java.util.Set[])}.
 *///from w  w w  .  j  a  v a  2s  .c  o m
@Test
@SuppressWarnings("unchecked")
public void testDeleteMixedSet() {
    Set deleteSet = new HashSet();
    deleteSet.add(gto2);
    deleteSet.add(gto3);
    Set[] setArray = new Set[] { deleteSet };
    genericDao.deleteMixedSet(setArray);

    List<CrazyTestObject> l = genericDao.findAll(CrazyTestObject.class);
    assertNotNull(l);
    assertEquals(4, l.size());
    assertTrue(!l.contains(gto2));
    assertTrue(!l.contains(gto3));

    // Now check that invalid objects cause failure
    deleteSet = new HashSet();
    deleteSet.add(gto1);
    Set deleteFailSet = new HashSet();
    deleteFailSet.add("string"); // non-matching object type
    deleteFailSet.add("string2"); // non-matching object type
    setArray = new Set[] { deleteSet, deleteFailSet };
    try {
        genericDao.deleteMixedSet(setArray);
        fail("Should have thrown an exception before getting here");
    } catch (IllegalArgumentException e) {
        assertNotNull(e);
    } catch (Exception e) {
        fail("Threw wrong exception: (" + e.getCause() + "): " + e.getMessage());
    }

    l = genericDao.findAll(CrazyTestObject.class);
    assertNotNull(l);
    assertEquals(4, l.size());
    assertTrue(l.contains(gto1));
    assertTrue(!l.contains(gto2));
    assertTrue(!l.contains(gto3));
}

From source file:org.sakaiproject.genericdao.springjdbc.CrazyGenericDaoTest.java

/**
 * Test method for {@link org.sakaiproject.genericdao.hibernate.HibernateCompleteGenericDao#saveMixedSet(java.util.Set[])}.
 *//*from  ww w.  ja  v a2 s .c o m*/
@Test
@SuppressWarnings("unchecked")
public void testSaveMixedSet() {
    CrazyTestObject gtoA = new CrazyTestObject("titleA", Boolean.TRUE);
    CrazyTestObject gtoB = new CrazyTestObject("titleB", Boolean.FALSE);
    Set saveSet = new HashSet();
    saveSet.add(gtoA);
    saveSet.add(gtoB);
    Set[] setArray = new Set[] { saveSet };
    genericDao.saveMixedSet(setArray);

    List<CrazyTestObject> l = genericDao.findAll(CrazyTestObject.class);
    assertNotNull(l);
    assertEquals(8, l.size());

    CrazyTestObject gtoC = new CrazyTestObject("titleC", Boolean.TRUE);
    saveSet = new HashSet<CrazyTestObject>();
    gto3.setTitle("XXXXX");
    saveSet.add(gto3);
    saveSet.add(gtoC);
    setArray = new Set[] { saveSet };
    genericDao.saveMixedSet(setArray);

    CrazyTestObject one = genericDao.findById(CrazyTestObject.class, gto3.getId());
    assertEquals("XXXXX", one.getTitle());

    l = genericDao.findAll(CrazyTestObject.class);
    assertNotNull(l);
    assertEquals(9, l.size());

    // Now check that invalid objects cause failure
    Set saveFailSet = new HashSet();
    saveFailSet.add("string"); // non-matching object type
    saveFailSet.add("string2"); // non-matching object type
    CrazyTestObject gtoD = new CrazyTestObject("titleD", Boolean.TRUE);
    saveSet = new HashSet();
    saveSet.add(gtoD);
    setArray = new Set[] { saveSet, saveFailSet };
    try {
        genericDao.saveMixedSet(setArray);
        fail("Should have thrown an exception before getting here");
    } catch (IllegalArgumentException e) {
        assertNotNull(e);
    } catch (Exception e) {
        fail("Threw wrong exception: (" + e.getCause() + "): " + e.getMessage());
    }

    l = genericDao.findAll(CrazyTestObject.class);
    assertNotNull(l);
    assertEquals(9, l.size());
    assertTrue(!l.contains(gtoD));
}

From source file:org.sakaiproject.genericdao.springjdbc.CrazyGenericDaoTest.java

/**
 * Test method for {@link org.sakaiproject.genericdao.hibernate.HibernateCompleteGenericDao#saveSet(java.util.Set)}.
 *//*w ww  .  j a va  2  s  . c o m*/
@Test
public void testSaveSet() {
    CrazyTestObject gtoA = new CrazyTestObject("titleA", Boolean.TRUE);
    CrazyTestObject gtoB = new CrazyTestObject("titleB", Boolean.FALSE);
    // batch insert
    Set<CrazyTestObject> saveSet = new HashSet<CrazyTestObject>();
    saveSet.add(gtoA);
    saveSet.add(gtoB);
    genericDao.saveSet(saveSet);

    List<CrazyTestObject> l = genericDao.findAll(CrazyTestObject.class);
    assertNotNull(l);
    assertEquals(8, l.size());

    // batch updates
    saveSet = new HashSet<CrazyTestObject>();
    gto1.setTitle("XXXXX");
    gto2.setTitle("XXXXX");
    saveSet.add(gto1);
    saveSet.add(gto2);
    genericDao.saveSet(saveSet);

    CrazyTestObject one = genericDao.findById(CrazyTestObject.class, gto1.getId());
    assertEquals("XXXXX", one.getTitle());
    CrazyTestObject two = genericDao.findById(CrazyTestObject.class, gto2.getId());
    assertEquals("XXXXX", two.getTitle());

    // Now try to cause various Exceptions

    // save empty set is OK
    genericDao.saveSet(new HashSet<CrazyTestObject>());

    //    test no longer needed
    //       CrazyTestObject gtoC = new CrazyTestObject("titleC", Boolean.TRUE);
    //       saveSet = new HashSet<CrazyTestObject>();
    //       saveSet.add(gtoC);
    //       saveSet.add("string"); // mixed types
    //       try {
    //       genericDao.saveSet(saveSet);
    //       fail("Should have thrown an exception before getting here");
    //       } catch (IllegalArgumentException e) {
    //       assertNotNull(e);
    //       } catch (Exception e) {
    //       fail("Threw wrong exception: ("+e.getCause()+"): " + e.getMessage());
    //       }

    //       l = genericDao.findAll(CrazyTestObject.class);
    //       assertNotNull(l);
    //       assertEquals(7, l.size());
    //       assertTrue(! l.contains(gtoC));

    Set<String> failSaveSet = new HashSet<String>();
    failSaveSet.add("string"); // not a persistent type
    try {
        genericDao.saveSet(failSaveSet);
        fail("Should have thrown an exception before getting here");
    } catch (IllegalArgumentException e) {
        assertNotNull(e);
    } catch (Exception e) {
        fail("Threw wrong exception: (" + e.getCause() + "): " + e.getMessage());
    }

    l = genericDao.findAll(CrazyTestObject.class);
    assertNotNull(l);
    assertEquals(8, l.size());
}

From source file:nl.b3p.viewer.stripes.SplitFeatureActionBean.java

public Resolution split() throws JSONException {
    JSONObject json = new JSONObject();

    json.put("success", Boolean.FALSE);
    String error = null;/*from ww  w . ja  va  2 s  . c  o  m*/

    if (appLayer == null) {
        error = "Invalid parameters";
    } else if (unauthorized) {
        error = "Not authorized";
    } else {
        FeatureSource fs = null;
        try {
            if (this.splitFeatureFID == null) {
                throw new IllegalArgumentException(getBundle().getString("viewer.splitfeatureactionbean.1"));
            }
            if (this.toSplitWithFeature == null) {
                throw new IllegalArgumentException(getBundle().getString("viewer.splitfeatureactionbean.2"));
            }

            fs = this.layer.getFeatureType().openGeoToolsFeatureSource();
            if (!(fs instanceof SimpleFeatureStore)) {
                throw new IllegalArgumentException(getBundle().getString("viewer.splitfeatureactionbean.3"));
            }
            this.store = (SimpleFeatureStore) fs;

            List<FeatureId> ids = this.splitFeature();

            if (ids.size() < 2) {
                throw new IllegalArgumentException(getBundle().getString("viewer.splitfeatureactionbean.4"));
            }

            json.put("fids", ids);
            json.put("success", Boolean.TRUE);
        } catch (IllegalArgumentException e) {
            log.warn("Split error", e);
            error = e.getLocalizedMessage();
        } catch (Exception e) {
            log.error(String.format("Exception splitting feature %s", this.splitFeatureFID), e);
            error = e.toString();
            if (e.getCause() != null) {
                error += "; cause: " + e.getCause().toString();
            }
        } finally {
            if (fs != null) {
                fs.getDataStore().dispose();
            }
        }
    }

    if (error != null) {
        json.put("error", error);
    }
    return new StreamingResolution("application/json", new StringReader(json.toString()));
}

From source file:org.sakaiproject.genericdao.springjdbc.CrazyGenericDaoTest.java

/**
 * Test method for {@link org.sakaiproject.genericdao.hibernate.HibernateCompleteGenericDao#deleteSet(java.util.Set)}.
 *///w  ww . j  av a  2  s  .  com
@Test
public void testDeleteSet() {
    Set<CrazyTestObject> deleteSet = new HashSet<CrazyTestObject>();
    deleteSet.add(gto1);
    deleteSet.add(gto2);
    genericDao.deleteSet(deleteSet);

    List<CrazyTestObject> l = genericDao.findAll(CrazyTestObject.class);
    assertNotNull(l);
    assertEquals(4, l.size());
    assertTrue(!l.contains(gto1));
    assertTrue(!l.contains(gto2));

    // delete nothing is ok
    genericDao.deleteSet(new HashSet<CrazyTestObject>());

    // Now try to cause various Exceptions
    //       test no longer needed
    //       Set<CrazyTestObject> deleteFailSet = new HashSet<CrazyTestObject>();
    //       deleteFailSet.add(gto4);
    //       deleteFailSet.add("string"); // non-matching object type
    //       try {
    //       genericDao.deleteSet(deleteFailSet);
    //       fail("Should have thrown an exception before getting here");
    //       } catch (IllegalArgumentException e) {
    //       assertNotNull(e);
    //       } catch (Exception e) {
    //       fail("Threw wrong exception: ("+e.getCause()+"): " + e.getMessage());
    //       }

    //       l = genericDao.findAll(CrazyTestObject.class);
    //       assertNotNull(l);
    //       assertEquals(3, l.size());
    //       assertTrue(l.contains(gto4));

    Set<String> deleteFailSet = new HashSet<String>();
    deleteFailSet.add("string"); // non-persistent object type
    try {
        genericDao.deleteSet(deleteFailSet);
        fail("Should have thrown an exception before getting here");
    } catch (IllegalArgumentException e) {
        assertNotNull(e);
    } catch (Exception e) {
        fail("Threw wrong exception: (" + e.getCause() + "): " + e.getMessage());
    }

    l = genericDao.findAll(CrazyTestObject.class);
    assertNotNull(l);
    assertEquals(4, l.size());
    assertTrue(l.contains(gto4));

    // had to remove this test because it depends on order -AZ
    //       CrazyTestObject gto = new CrazyTestObject("title", Boolean.TRUE);
    //       deleteFailSet = new HashSet();
    //       // I don't like that order is important for this test to work... -AZ
    //       deleteFailSet.add(gto); // object is not in the DB
    //       deleteFailSet.add(gto4);
    //       try {
    //       genericDao.deleteSet(deleteFailSet);
    //       fail("Should have thrown an exception before getting here");
    //       } catch (InvalidDataAccessApiUsageException e) {
    //       assertNotNull(e);
    //       } catch (Exception e) {
    //       fail("Threw wrong exception: ("+e.getCause()+"): " + e.getMessage());
    //       }

    //       l = genericDao.findAll(CrazyTestObject.class);
    //       assertNotNull(l);
    //       assertEquals(3, l.size());
    //       assertTrue(l.contains(gto4));
}

From source file:org.apache.sentry.cli.tools.TestSentryShellKafka.java

@Test
public void testNegativeCaseWithoutRequiredArgument() throws Exception {
    runTestAsSubject(new TestOperation() {
        @Override/*from  w ww .  java  2 s  . c  o  m*/
        public void runTestAsSubject() throws Exception {
            String strOptionConf = "conf";
            client.createRole(requestorName, TEST_ROLE_NAME_1, KAFKA);
            // test: the conf is required argument
            String[] args = { "-cr", "-r", TEST_ROLE_NAME_1, "-t", "kafka" };
            SentryShellGeneric sentryShell = new SentryShellGeneric();
            validateMissingParameterMsg(sentryShell, args,
                    SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + strOptionConf);

            // test: -r is required when create role
            args = new String[] { "-cr", "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
            sentryShell = new SentryShellGeneric();
            validateMissingParameterMsg(sentryShell, args,
                    SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);

            // test: -r is required when drop role
            args = new String[] { "-dr", "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
            sentryShell = new SentryShellGeneric();
            validateMissingParameterMsg(sentryShell, args,
                    SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);

            // test: -r is required when add role to group
            args = new String[] { "-arg", "-g", "testGroup1", "-conf", confPath.getAbsolutePath(), "-t",
                    "kafka" };
            sentryShell = new SentryShellGeneric();
            validateMissingParameterMsg(sentryShell, args,
                    SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);

            // test: -g is required when add role to group
            args = new String[] { "-arg", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath(), "-t",
                    "kafka" };
            sentryShell = new SentryShellGeneric();
            validateMissingParameterMsg(sentryShell, args,
                    SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_GROUP_NAME);

            // test: -r is required when delete role from group
            args = new String[] { "-drg", "-g", "testGroup1", "-conf", confPath.getAbsolutePath(), "-t",
                    "kafka" };
            sentryShell = new SentryShellGeneric();
            validateMissingParameterMsg(sentryShell, args,
                    SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);

            // test: -g is required when delete role from group
            args = new String[] { "-drg", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath(), "-t",
                    "kafka" };
            sentryShell = new SentryShellGeneric();
            validateMissingParameterMsg(sentryShell, args,
                    SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_GROUP_NAME);

            // test: -r is required when grant privilege to role
            args = new String[] { "-gpr", "-p", "server=server1", "-conf", confPath.getAbsolutePath(), "-t",
                    "kafka" };
            sentryShell = new SentryShellGeneric();
            validateMissingParameterMsg(sentryShell, args,
                    SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);

            // test: -p is required when grant privilege to role
            args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-t",
                    "kafka" };
            sentryShell = new SentryShellGeneric();
            validateMissingParameterMsg(sentryShell, args,
                    SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_PRIVILEGE);

            // test: action is required in privilege
            args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-p",
                    "host=*->topic=t1", "-t", "kafka" };
            sentryShell = new SentryShellGeneric();
            try {
                getShellResultWithOSRedirect(sentryShell, args, false);
                fail("Expected IllegalArgumentException");
            } catch (IllegalArgumentException e) {
                assert (("Kafka privilege must end with a valid action.\n"
                        + KafkaPrivilegeValidator.KafkaPrivilegeHelpMsg).equals(e.getCause().getMessage()));
            } catch (Exception e) {
                fail("Unexpected exception received. " + e);
            }

            // test: -r is required when revoke privilege from role
            args = new String[] { "-rpr", "-p", "host=h1", "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
            sentryShell = new SentryShellGeneric();
            validateMissingParameterMsg(sentryShell, args,
                    SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);

            // test: -p is required when revoke privilege from role
            args = new String[] { "-rpr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-t",
                    "kafka" };
            sentryShell = new SentryShellGeneric();
            validateMissingParameterMsg(sentryShell, args,
                    SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_PRIVILEGE);

            // test: command option is required for shell
            args = new String[] { "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
            sentryShell = new SentryShellGeneric();
            validateMissingParameterMsgsContains(sentryShell, args,
                    SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + "[", "-arg Add role to group",
                    "-cr Create role", "-rpr Revoke privilege from role", "-drg Delete role from group",
                    "-lr List role", "-lp List privilege", "-gpr Grant privilege to role", "-dr Drop role");

            // clear the test data
            client.dropRole(requestorName, TEST_ROLE_NAME_1, KAFKA);
        }
    });
}

From source file:com.daro.persistence.generic.dao.GenericDaoImpl.java

/**
 * Persist new entity p.//w  ww  .j  a v a 2s  .  com
 * 
 * @param p Data type of entity.
 * @throws PersistenceException
 */
@Override
public void add(T p) throws PersistenceException {

    Session session = this.getCurrentSession();

    try {
        session.persist(p);
    } catch (java.lang.IllegalArgumentException illegalArgumentEx) {
        logger.error("Persistence layer error: " + illegalArgumentEx.getStackTrace());
        PersistenceError error;
        if (p == null) {
            error = PersistenceError.ENTITY_NULL;
        } else {
            error = PersistenceError.PERSISTENCE_INTERNAL_ERROR;
        }
        throw new PersistenceException(error, illegalArgumentEx.getCause());
    }

    if (loggerInfoEnabled)
        logger.debug("Persistence layer info: " + "Saved successfully, Details=" + p);
}

From source file:com.daro.persistence.generic.dao.GenericDaoImpl.java

/**
 * Update entity p. Persists existing entity p.
 * //from ww w .  j  a  v  a  2s .c om
 * @param p T Data type of entity
 * @throws PersistenceException
 */
@Override
public void update(T p) throws PersistenceException {
    Session session = this.getCurrentSession();

    try {
        //session.update(p);
        session.merge(p);
    } catch (java.lang.IllegalArgumentException illegalArgumentEx) {
        logger.error("Persistence layer error: " + illegalArgumentEx.getStackTrace());
        PersistenceError error;
        if (p == null) {
            error = PersistenceError.ENTITY_NULL;
        } else {
            error = PersistenceError.PERSISTENCE_INTERNAL_ERROR;
        }
        throw new PersistenceException(error, illegalArgumentEx.getCause());
    }

    if (loggerInfoEnabled)
        logger.debug("Persistence layer info: " + "Person updated successfully, Person Details=" + p);
}

From source file:com.qmetry.qaf.automation.step.JavaStep.java

@Override
protected Object doExecute() {
    try {/*from   w ww.j  a va 2  s  .  c o m*/
        Object stepProvider = getStepProvider();
        // block joint-point listener
        TestBaseProvider.instance().get().getContext().setProperty(ATTACH_LISTENER, false);
        TestBaseProvider.instance().get().getContext().setProperty("current.teststep", this);
        method.setAccessible(true);
        return method.invoke(stepProvider, processArgs(method, actualArgs));
    } catch (IllegalArgumentException e) {
        throw new StepInvocationException(this, "Unable to invoke JavaStep with given arguments: " + getName()
                + Arrays.toString(actualArgs) + "\nat " + getSignature(), true);

    } catch (IllegalAccessException e) {
        throw new StepInvocationException(this, "Unable to invoke JavaStep: " + getName()
                + Arrays.toString(actualArgs) + "\nat " + getSignature(), true);

    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof Error) {
            throw (Error) e.getCause();
        }
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw new StepInvocationException(this, e.getCause());
    } catch (InstantiationException e) {
        throw new StepInvocationException(this,
                "Unable to Instantiate JavaStep: " + getName() + Arrays.toString(actualArgs) + getSignature(),
                true);
    }
}

From source file:nl.b3p.viewer.stripes.MergeFeaturesActionBean.java

public Resolution merge() throws JSONException {
    JSONObject json = new JSONObject();
    json.put("success", Boolean.FALSE);
    String error = null;/*from w  w w .  j  ava2  s. c o m*/

    if (appLayer == null) {
        error = getBundle().getString("viewer.mergefeaturesactionbean.1");
    } else if (unauthorized) {
        error = getBundle().getString("viewer.mergefeaturesactionbean.2");
    } else {
        FeatureSource fs = null;
        try {
            if (this.fidA == null || this.fidB == null) {
                throw new IllegalArgumentException(getBundle().getString("viewer.mergefeaturesactionbean.3"));
            }
            if (this.strategy == null) {
                throw new IllegalArgumentException(getBundle().getString("viewer.mergefeaturesactionbean.4"));
            }

            fs = this.layer.getFeatureType().openGeoToolsFeatureSource();
            if (!(fs instanceof SimpleFeatureStore)) {
                throw new IllegalArgumentException(getBundle().getString("viewer.mergefeaturesactionbean.5"));
            }
            this.store = (SimpleFeatureStore) fs;

            List<FeatureId> ids = this.mergeFeatures();

            if (ids.isEmpty()) {
                throw new IllegalArgumentException(getBundle().getString("viewer.mergefeaturesactionbean.6"));
            }

            if (ids.size() > 1) {
                throw new IllegalArgumentException(getBundle().getString("viewer.mergefeaturesactionbean.7"));
            }

            json.put("fids", ids);
            json.put("success", Boolean.TRUE);
        } catch (IllegalArgumentException e) {
            LOG.warn("Merge error", e);
            error = e.getLocalizedMessage();
        } catch (Exception e) {
            LOG.error(MessageFormat.format(getBundle().getString("viewer.mergefeaturesactionbean.8"), this.fidB,
                    this.fidA, e));
            error = e.toString();
            if (e.getCause() != null) {
                error += "; cause: " + e.getCause().toString();
            }
        } finally {
            if (fs != null) {
                fs.getDataStore().dispose();
            }
        }
    }

    if (error != null) {
        json.put("error", error);
    }
    return new StreamingResolution("application/json", new StringReader(json.toString()));
}