Example usage for java.lang.reflect InvocationTargetException getCause

List of usage examples for java.lang.reflect InvocationTargetException getCause

Introduction

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

Prototype

public Throwable getCause() 

Source Link

Document

Returns the cause of this exception (the thrown target exception, which may be null ).

Usage

From source file:org.apache.hadoop.hive.metastore.MetaStoreUtils.java

/**
 * create listener instances as per the configuration.
 *
 * @param clazz//  w w  w. jav a 2  s.co  m
 * @param conf
 * @param listenerImplList
 * @return
 * @throws MetaException
 */
static <T> List<T> getMetaStoreListeners(Class<T> clazz, HiveConf conf, String listenerImplList)
        throws MetaException {
    List<T> listeners = new ArrayList<T>();

    if (StringUtils.isBlank(listenerImplList)) {
        return listeners;
    }

    String[] listenerImpls = listenerImplList.split(",");
    for (String listenerImpl : listenerImpls) {
        try {
            T listener = (T) Class.forName(listenerImpl.trim(), true, JavaUtils.getClassLoader())
                    .getConstructor(Configuration.class).newInstance(conf);
            listeners.add(listener);
        } catch (InvocationTargetException ie) {
            throw new MetaException(
                    "Failed to instantiate listener named: " + listenerImpl + ", reason: " + ie.getCause());
        } catch (Exception e) {
            throw new MetaException("Failed to instantiate listener named: " + listenerImpl + ", reason: " + e);
        }
    }

    return listeners;
}

From source file:org.eclipse.wb.tests.designer.core.util.jdt.core.CodeUtilsTest.java

private void check_clearHiddenCode(String[] lines, String[] expectedLines) throws Exception {
    String source = StringUtils.join(lines, "\n");
    String expectedSource = StringUtils.join(expectedLines, "\n");
    try {/*from  w ww.  j  av  a 2 s.  c  o m*/
        String clearedSource = (String) ReflectionUtils.invokeMethod(CodeUtils.class,
                "clearHiddenCode(java.lang.String)", source);
        assertEquals(expectedSource, clearedSource);
    } catch (InvocationTargetException e) {
        throw (Exception) e.getCause();
    }
}

From source file:org.zuinnote.hadoop.office.format.common.parser.msexcel.MSExcelParser.java

private List<String> getLinkedWorkbooksHSSF() {
    List<String> result = new ArrayList<>();
    try {/*from  w w w . j a  v a 2s .  c  o  m*/
        // this is a hack to fetch linked workbooks in the Old Excel format
        // we use reflection to access private fields
        // might not work if internal structure of the class changes
        InternalWorkbook intWb = ((HSSFWorkbook) this.currentWorkbook).getInternalWorkbook();
        // method to fetch link table
        Method linkTableMethod = InternalWorkbook.class.getDeclaredMethod("getOrCreateLinkTable");
        linkTableMethod.setAccessible(true);
        Object linkTable = linkTableMethod.invoke(intWb);
        // method to fetch external book and sheet name
        Method externalBooksMethod = linkTable.getClass().getDeclaredMethod("getExternalBookAndSheetName",
                int.class);
        externalBooksMethod.setAccessible(true);
        // now we need to browse through the table until we hit an array out of bounds
        int i = 0;
        try {
            while (i < MSExcelParser.MAX_LINKEDWB_OLDEXCEL) {
                String[] externalBooks = (String[]) externalBooksMethod.invoke(linkTable, i++);
                if ((externalBooks != null) && (externalBooks.length > 0)) {
                    result.add(externalBooks[0]);
                }
            }
        } catch (java.lang.reflect.InvocationTargetException e) {
            if (!(e.getCause() instanceof java.lang.IndexOutOfBoundsException)) {
                throw e;
            }
        }

    } catch (NoSuchMethodException nsme) {
        LOG.error(COULD_NOT_RETRIEVE_LINKED_WORKBOOKS_FOR_OLD_EXCEL_FORMAT);
        LOG.error(nsme);
    } catch (IllegalAccessException iae) {
        LOG.error(COULD_NOT_RETRIEVE_LINKED_WORKBOOKS_FOR_OLD_EXCEL_FORMAT);
        LOG.error(iae);
    } catch (InvocationTargetException ite) {
        LOG.error(COULD_NOT_RETRIEVE_LINKED_WORKBOOKS_FOR_OLD_EXCEL_FORMAT);
        LOG.error(ite);
    }
    return result;
}

From source file:com.intel.moe.frameworks.inapppurchase.android.util.IabHelper.java

/**
 * Initiate the UI flow for an in-app purchase. Call this method to initiate an in-app purchase,
 * which will involve bringing up the Google Play screen. The calling activity will be paused while
 * the user interacts with Google Play, and the result will be delivered via the activity's
 * {@link Activity#onActivityResult} method, at which point you must call
 * this object's {@link #handleActivityResult} method to continue the purchase flow. This method
 * MUST be called from the UI thread of the Activity.
 *
 * @param act The calling activity.//from w w w  .  j  a v a2  s  .  c om
 * @param sku The sku of the item to purchase.
 * @param itemType indicates if it's a product or a subscription (ITEM_TYPE_INAPP or ITEM_TYPE_SUBS)
 * @param requestCode A request code (to differentiate from other responses --
 *     as in {@link Activity#startActivityForResult}).
 * @param listener The listener to notify when the purchase process finishes
 * @param extraData Extra data (developer payload), which will be returned with the purchase data
 *     when the purchase completes. This extra data will be permanently bound to that purchase
 *     and will always be returned when the purchase is queried.
 */
public void launchPurchaseFlow(Object act, String sku, String itemType, int requestCode,
        OnIabPurchaseFinishedListener listener, String extraData) {
    checkNotDisposed();
    checkSetupDone("launchPurchaseFlow");
    flagStartAsync("launchPurchaseFlow");
    IabResult result;

    if (itemType.equals(ITEM_TYPE_SUBS) && !mSubscriptionsSupported) {
        IabResult r = new IabResult(IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE, "Subscriptions are not available.");
        flagEndAsync();
        if (listener != null)
            listener.onIabPurchaseFinished(r, null);
        return;
    }

    try {
        logDebug("Constructing buy intent for " + sku + ", item type: " + itemType);
        Bundle buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, itemType, extraData);
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            logError("Unable to buy item, Error response: " + getResponseDesc(response));
            flagEndAsync();
            result = new IabResult(response, "Unable to buy item");
            if (listener != null)
                listener.onIabPurchaseFinished(result, null);
            return;
        }

        PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
        logDebug("Launching buy intent for " + sku + ". Request code: " + requestCode);
        mRequestCode = requestCode;
        mPurchaseListener = listener;
        mPurchasingItemType = itemType;
        Class activityClass = Class.forName("android.app.Activity");

        Class[] paramTypes = new Class[] { IntentSender.class, int.class, Intent.class, int.class, int.class,
                int.class };
        Method method = activityClass.getMethod("startIntentSenderForResult", paramTypes);

        Object[] args = new Object[] { pendingIntent.getIntentSender(), requestCode, new Intent(),
                Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0) };

        method.invoke(act, args);
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof IntentSender.SendIntentException) {
            logError("SendIntentException while launching purchase flow for sku " + sku);
            e.printStackTrace();
            flagEndAsync();

            result = new IabResult(IABHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
            if (listener != null)
                listener.onIabPurchaseFinished(result, null);
        }
    } catch (RemoteException e) {
        logError("RemoteException while launching purchase flow for sku " + sku);
        e.printStackTrace();
        flagEndAsync();

        result = new IabResult(IABHELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow");
        if (listener != null)
            listener.onIabPurchaseFinished(result, null);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}

From source file:rb.app.TransientRBSystem.java

/**
 * Set the Q_a variable from the mTheta object.
 *//*from ww w.j  a  v a2s.com*/
protected void read_in_Q_m() {
    Method meth;

    try {
        // Get a reference to get_n_A_functions, which does not
        // take any arguments
        meth = mAffineFnsClass.getMethod("get_n_M_functions", null);
    } catch (NoSuchMethodException nsme) {
        throw new RuntimeException("getMethod for get_n_M_functions failed", nsme);
    }

    Integer Q_m;
    try {
        Object Q_m_obj = meth.invoke(mTheta, null);
        Q_m = (Integer) Q_m_obj;
    } catch (IllegalAccessException iae) {
        throw new RuntimeException(iae);
    } catch (InvocationTargetException ite) {
        throw new RuntimeException(ite.getCause());
    }

    mQ_m = Q_m.intValue();
}

From source file:rb.app.TransientRBSystem.java

/**
 * Evaluate theta_q_m (for the q^th mass matrix term) at the current parameter.
 *//*from   www .  ja  v  a  2  s . co m*/
public double eval_theta_q_m(int q) {
    Method meth;

    try {
        // Get a reference to get_n_M_functions, which does not
        // take any arguments

        Class partypes[] = new Class[2];
        partypes[0] = Integer.TYPE;
        partypes[1] = double[].class;

        meth = mAffineFnsClass.getMethod("evaluateM", partypes);
    } catch (NoSuchMethodException nsme) {
        throw new RuntimeException("getMethod for evaluateM failed", nsme);
    }

    Double theta_val;
    try {
        Object arglist[] = new Object[2];
        arglist[0] = new Integer(q);
        arglist[1] = current_parameters.getArray();

        Object theta_obj = meth.invoke(mTheta, arglist);
        theta_val = (Double) theta_obj;
    } catch (IllegalAccessException iae) {
        throw new RuntimeException(iae);
    } catch (InvocationTargetException ite) {
        throw new RuntimeException(ite.getCause());
    }

    return theta_val.doubleValue();
}

From source file:io.personium.core.model.impl.fs.DavCmpFsImplTest.java

/**
 * Test doPutForUpdate()./*  w w w. j  a  va2s  . co m*/
 * Error case.
 * ETag not match.
 * @throws Exception Unintended exception in test
 */
@Test
public void doPutForUpdate_Error_Not_match_ETag() throws Exception {
    String contentPath = TEST_DIR_PATH + CONTENT_FILE;
    String tempContentPath = TEST_DIR_PATH + TEMP_CONTENT_FILE;
    File contentFile = new File(contentPath);
    File tempContentFile = new File(tempContentPath);
    try {
        contentFile.createNewFile();
        // Test method args
        String contentType = "application/json";
        InputStream inputStream = getSystemResourceAsStream("request/unit/cell-create.txt");
        String etag = "\"1-1487652733383\"";

        // Expected result
        boolean contentFileExists = true;
        boolean tempFileExists = false;
        FileInputStream sourceStream = new FileInputStream(contentFile);
        String sourceFileMD5 = md5Hex(sourceStream);
        sourceStream.close();

        // Mock settings
        davCmpFsImpl = PowerMockito.spy(DavCmpFsImpl.create("", null));
        doNothing().when(davCmpFsImpl).load();
        doReturn(true).when(davCmpFsImpl).exists();
        PowerMockito.doReturn(false).when(davCmpFsImpl, "matchesETag", anyString());

        // Load methods for private
        Method method = DavCmpFsImpl.class.getDeclaredMethod("doPutForUpdate", String.class, InputStream.class,
                String.class);
        method.setAccessible(true);

        // Run method
        try {
            method.invoke(davCmpFsImpl, contentType, inputStream, etag);
            fail("Not throws exception.");
        } catch (InvocationTargetException e) {
            // Confirm result
            assertThat(e.getCause(), is(instanceOf(PersoniumCoreException.class)));
            PersoniumCoreException exception = (PersoniumCoreException) e.getCause();
            assertThat(exception.getCode(), is(PersoniumCoreException.Dav.ETAG_NOT_MATCH.getCode()));
        }
        assertThat(contentFile.exists(), is(contentFileExists));
        assertThat(tempContentFile.exists(), is(tempFileExists));
        FileInputStream contentStream = new FileInputStream(contentFile);
        assertThat(md5Hex(contentStream), is(sourceFileMD5));

        inputStream.close();
        contentStream.close();
    } finally {
        contentFile.delete();
        tempContentFile.delete();
    }
}

From source file:rb.app.RBSystem.java

/**
 * Set the Q_f variable from the mTheta object.
 *//*from w  w w . ja  v a2  s  . co  m*/
protected void read_in_Q_f() {
    Method meth;

    try {
        // Get a reference to get_n_F_functions, which does not
        // take any arguments
        meth = mAffineFnsClass.getMethod("get_n_F_functions", null);
    } catch (NoSuchMethodException nsme) {
        throw new RuntimeException("getMethod for get_n_F_functions failed", nsme);
    }

    Integer Q_f;
    try {
        Object Q_f_obj = meth.invoke(mTheta, null);
        Q_f = (Integer) Q_f_obj;
    } catch (IllegalAccessException iae) {
        throw new RuntimeException(iae);
    } catch (InvocationTargetException ite) {
        throw new RuntimeException(ite.getCause());
    }

    mQ_f = Q_f.intValue();
}

From source file:rb.app.RBSystem.java

/**
 * Set the n_outputs variable from the mTheta object.
 *///from   w  w w  .  j  a va 2  s  . c  o m
protected void read_in_n_outputs() {
    Method meth;

    try {
        // Get a reference to get_n_L_functions, which does not
        // take any arguments
        meth = mAffineFnsClass.getMethod("get_n_outputs", null);
    } catch (NoSuchMethodException nsme) {
        throw new RuntimeException("getMethod for get_n_outputs failed", nsme);
    }

    Integer n_outputs;
    try {
        Object n_outputs_obj = meth.invoke(mTheta, null);
        n_outputs = (Integer) n_outputs_obj;
    } catch (IllegalAccessException iae) {
        throw new RuntimeException(iae);
    } catch (InvocationTargetException ite) {
        throw new RuntimeException(ite.getCause());
    }

    mN_outputs = n_outputs.intValue();
}

From source file:rb.app.RBSystem.java

/**
 * @param output_index The index of the output we are interested in
 * @return the number of terms in the affine expansion of the specified output
 *//*from   w w w.j  a v a2s.  c  om*/
protected int get_Q_l(int output_index) {
    Method meth;

    try {
        // Get a reference to get_Q_l, which takes an int argument
        Class partypes[] = new Class[1];
        partypes[0] = Integer.TYPE;
        meth = mAffineFnsClass.getMethod("get_Q_l", partypes);
    } catch (NoSuchMethodException nsme) {
        throw new RuntimeException("getMethod for get_Q_l failed", nsme);
    }

    Integer Q_l;
    try {
        Object arglist[] = new Object[1];
        arglist[0] = new Integer(output_index);
        Object Q_l_obj = meth.invoke(mTheta, arglist);
        Q_l = (Integer) Q_l_obj;
    } catch (IllegalAccessException iae) {
        throw new RuntimeException(iae);
    } catch (InvocationTargetException ite) {
        throw new RuntimeException(ite.getCause());
    }

    return Q_l.intValue();
}