Search in sources :

Example 1 with NullPointerException

use of java.lang.NullPointerException in project DeepLinkDispatch by airbnb.

the class DeepLinkDelegate method dispatchFrom.

public DeepLinkResult dispatchFrom(Activity activity, Intent sourceIntent) {
    if (activity == null) {
        throw new NullPointerException("activity == null");
    }
    if (sourceIntent == null) {
        throw new NullPointerException("sourceIntent == null");
    }
    Uri uri = sourceIntent.getData();
    if (uri == null) {
        return createResultAndNotify(activity, false, null, "No Uri in given activity's intent.");
    }
    String uriString = uri.toString();
    DeepLinkEntry entry = findEntry(uriString);
    if (entry != null) {
        DeepLinkUri deepLinkUri = DeepLinkUri.parse(uriString);
        Map<String, String> parameterMap = entry.getParameters(uriString);
        for (String queryParameter : deepLinkUri.queryParameterNames()) {
            for (String queryParameterValue : deepLinkUri.queryParameterValues(queryParameter)) {
                if (parameterMap.containsKey(queryParameter)) {
                    Log.w(TAG, "Duplicate parameter name in path and query param: " + queryParameter);
                }
                parameterMap.put(queryParameter, queryParameterValue);
            }
        }
        parameterMap.put(DeepLink.URI, uri.toString());
        Bundle parameters;
        if (sourceIntent.getExtras() != null) {
            parameters = new Bundle(sourceIntent.getExtras());
        } else {
            parameters = new Bundle();
        }
        for (Map.Entry<String, String> parameterEntry : parameterMap.entrySet()) {
            parameters.putString(parameterEntry.getKey(), parameterEntry.getValue());
        }
        try {
            Class<?> c = entry.getActivityClass();
            Intent newIntent;
            TaskStackBuilder taskStackBuilder = null;
            if (entry.getType() == DeepLinkEntry.Type.CLASS) {
                newIntent = new Intent(activity, c);
            } else {
                Method method;
                try {
                    method = c.getMethod(entry.getMethod(), Context.class);
                    if (method.getReturnType().equals(TaskStackBuilder.class)) {
                        taskStackBuilder = (TaskStackBuilder) method.invoke(c, activity);
                        if (taskStackBuilder.getIntentCount() == 0) {
                            return createResultAndNotify(activity, false, uri, "Could not deep link to method: " + entry.getMethod() + " intents length == 0");
                        }
                        newIntent = taskStackBuilder.editIntentAt(taskStackBuilder.getIntentCount() - 1);
                    } else {
                        newIntent = (Intent) method.invoke(c, activity);
                    }
                } catch (NoSuchMethodException exception) {
                    method = c.getMethod(entry.getMethod(), Context.class, Bundle.class);
                    if (method.getReturnType().equals(TaskStackBuilder.class)) {
                        taskStackBuilder = (TaskStackBuilder) method.invoke(c, activity, parameters);
                        if (taskStackBuilder.getIntentCount() == 0) {
                            return createResultAndNotify(activity, false, uri, "Could not deep link to method: " + entry.getMethod() + " intents length == 0");
                        }
                        newIntent = taskStackBuilder.editIntentAt(taskStackBuilder.getIntentCount() - 1);
                    } else {
                        newIntent = (Intent) method.invoke(c, activity, parameters);
                    }
                }
            }
            if (newIntent.getAction() == null) {
                newIntent.setAction(sourceIntent.getAction());
            }
            if (newIntent.getData() == null) {
                newIntent.setData(sourceIntent.getData());
            }
            newIntent.putExtras(parameters);
            newIntent.putExtra(DeepLink.IS_DEEP_LINK, true);
            newIntent.putExtra(DeepLink.REFERRER_URI, uri);
            if (activity.getCallingActivity() != null) {
                newIntent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
            }
            if (taskStackBuilder != null) {
                taskStackBuilder.startActivities();
            } else {
                activity.startActivity(newIntent);
            }
            return createResultAndNotify(activity, true, uri, null);
        } catch (NoSuchMethodException exception) {
            return createResultAndNotify(activity, false, uri, "Deep link to non-existent method: " + entry.getMethod());
        } catch (IllegalAccessException exception) {
            return createResultAndNotify(activity, false, uri, "Could not deep link to method: " + entry.getMethod());
        } catch (InvocationTargetException exception) {
            return createResultAndNotify(activity, false, uri, "Could not deep link to method: " + entry.getMethod());
        }
    } else {
        return createResultAndNotify(activity, false, uri, "No registered entity to handle deep link: " + uri.toString());
    }
}
Also used : Context(android.content.Context) DeepLinkUri(com.airbnb.deeplinkdispatch.DeepLinkUri) Bundle(android.os.Bundle) Intent(android.content.Intent) String(java.lang.String) Method(java.lang.reflect.Method) DeepLinkUri(com.airbnb.deeplinkdispatch.DeepLinkUri) Uri(android.net.Uri) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchMethodException(java.lang.NoSuchMethodException) NullPointerException(java.lang.NullPointerException) DeepLinkEntry(com.airbnb.deeplinkdispatch.DeepLinkEntry) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) Map(java.util.Map)

Example 2 with NullPointerException

use of java.lang.NullPointerException in project jdk8u_jdk by JetBrains.

the class AppContextCreator method getResourceAsStream.

/**
     * Returns an input stream for reading the specified resource.
     *
     * The search order is described in the documentation for {@link
     * #getResource(String)}.<p>
     *
     * @param  name the resource name
     * @return an input stream for reading the resource, or <code>null</code>
     *         if the resource could not be found
     * @since  JDK1.1
     */
public InputStream getResourceAsStream(String name) {
    if (name == null) {
        throw new NullPointerException("name");
    }
    try {
        InputStream is = null;
        //
        synchronized (syncResourceAsStream) {
            resourceAsStreamInCall = true;
            // Call super class
            is = super.getResourceAsStream(name);
            resourceAsStreamInCall = false;
        }
        // during resource requests. [stanley.ho]
        if (codebaseLookup == true && is == null) {
            // If resource cannot be obtained,
            // try to download it from codebase
            URL url = new URL(base, ParseUtil.encodePath(name, false));
            is = url.openStream();
        }
        return is;
    } catch (Exception e) {
        return null;
    }
}
Also used : NullPointerException(java.lang.NullPointerException) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) URL(java.net.URL) NullPointerException(java.lang.NullPointerException) NoSuchElementException(java.util.NoSuchElementException) PrivilegedActionException(java.security.PrivilegedActionException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 3 with NullPointerException

use of java.lang.NullPointerException in project j2objc by google.

the class IvParameterSpecTest method testIvParameterSpec1.

/**
 * IvParameterSpec(byte[] iv) constructor testing. Checks that
 * NullPointerException is thrown in the case of null input
 * array and that input array is copied during initialization.
 */
public void testIvParameterSpec1() {
    try {
        new IvParameterSpec(null);
        fail("Should raise an NullPointerException " + "in the case of null byte array.");
    } catch (NullPointerException e) {
    }
    byte[] iv = new byte[] { 1, 2, 3, 4, 5 };
    IvParameterSpec ivps = new IvParameterSpec(iv);
    iv[0]++;
    assertFalse("The change of input array's content should not cause " + "the change of internal array", iv[0] == ivps.getIV()[0]);
}
Also used : NullPointerException(java.lang.NullPointerException) IvParameterSpec(javax.crypto.spec.IvParameterSpec)

Example 4 with NullPointerException

use of java.lang.NullPointerException in project robovm by robovm.

the class IvParameterSpecTest method testIvParameterSpec1.

/**
     * IvParameterSpec(byte[] iv) constructor testing. Checks that
     * NullPointerException is thrown in the case of null input
     * array and that input array is copied during initialization.
     */
public void testIvParameterSpec1() {
    try {
        new IvParameterSpec(null);
        fail("Should raise an NullPointerException " + "in the case of null byte array.");
    } catch (NullPointerException e) {
    }
    byte[] iv = new byte[] { 1, 2, 3, 4, 5 };
    IvParameterSpec ivps = new IvParameterSpec(iv);
    iv[0]++;
    assertFalse("The change of input array's content should not cause " + "the change of internal array", iv[0] == ivps.getIV()[0]);
}
Also used : NullPointerException(java.lang.NullPointerException) IvParameterSpec(javax.crypto.spec.IvParameterSpec)

Example 5 with NullPointerException

use of java.lang.NullPointerException in project robovm by robovm.

the class IvParameterSpecTest method testIvParameterSpec2.

/**
     * IvParameterSpec(byte[] iv) constructor testing. Checks that
     * NullPointerException is thrown in the case of null input
     * array and that input array is copied during initialization.
     */
public void testIvParameterSpec2() {
    try {
        new IvParameterSpec(null, 1, 1);
        fail("Should raise an IllegalArgumentException " + "in the case of null byte array.");
    } catch (ArrayIndexOutOfBoundsException e) {
        fail("Unexpected ArrayIndexOutOfBoundsException was thrown");
    } catch (IllegalArgumentException e) {
    } catch (NullPointerException e) {
        fail("Unexpected NullPointerException was thrown");
    }
    try {
        new IvParameterSpec(new byte[] { 1, 2, 3 }, 2, 2);
        fail("Should raise an IllegalArgumentException " + "if (iv.length - offset < len).");
    } catch (ArrayIndexOutOfBoundsException e) {
        fail("Unexpected ArrayIndexOutOfBoundsException was thrown");
    } catch (IllegalArgumentException e) {
    } catch (NullPointerException e) {
        fail("Unexpected NullPointerException was thrown");
    }
    try {
        new IvParameterSpec(new byte[] { 1, 2, 3 }, -1, 1);
        fail("Should raise an ArrayIndexOutOfBoundsException " + "if offset index bytes outside the iv.");
    } catch (ArrayIndexOutOfBoundsException e) {
    } catch (IllegalArgumentException e) {
        fail("Unexpected IllegalArgumentException was thrown");
    } catch (NullPointerException e) {
        fail("Unexpected NullPointerException was thrown");
    }
    /* TODO: DRL fail with java.lang.NegativeArraySizeException
        try {
            new IvParameterSpec(new byte[] {1, 2, 3}, 1, -2);
            fail("Should raise an ArrayIndexOutOfBoundsException "
                    + "if len index bytes outside the iv.");
        } catch(ArrayIndexOutOfBoundsException e) {
        } catch(IllegalArgumentException e) {
            fail("Unexpected IllegalArgumentException was thrown");
        } catch(NullPointerException e) {
            fail("Unexpected NullPointerException was thrown");
        }
        */
    byte[] iv = new byte[] { 1, 2, 3, 4, 5 };
    IvParameterSpec ivps = new IvParameterSpec(iv, 0, iv.length);
    iv[0]++;
    assertFalse("The change of input array's content should not cause " + "the change of internal array", iv[0] == ivps.getIV()[0]);
    //Regression for HARMONY-1089
    try {
        new IvParameterSpec(new byte[2], 2, -1);
        fail("ArrayIndexOutOfBoundsException expected");
    } catch (ArrayIndexOutOfBoundsException e) {
    //expected
    }
}
Also used : NullPointerException(java.lang.NullPointerException) IvParameterSpec(javax.crypto.spec.IvParameterSpec) ArrayIndexOutOfBoundsException(java.lang.ArrayIndexOutOfBoundsException) IllegalArgumentException(java.lang.IllegalArgumentException)

Aggregations

NullPointerException (java.lang.NullPointerException)8 IvParameterSpec (javax.crypto.spec.IvParameterSpec)4 Context (android.content.Context)2 BufferedInputStream (java.io.BufferedInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayIndexOutOfBoundsException (java.lang.ArrayIndexOutOfBoundsException)2 IllegalArgumentException (java.lang.IllegalArgumentException)2 NoSuchMethodException (java.lang.NoSuchMethodException)2 MalformedURLException (java.net.MalformedURLException)2 UnknownHostException (java.net.UnknownHostException)2 PrivilegedActionException (java.security.PrivilegedActionException)2 NoSuchElementException (java.util.NoSuchElementException)2 Intent (android.content.Intent)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)1 DeepLinkEntry (com.airbnb.deeplinkdispatch.DeepLinkEntry)1 DeepLinkUri (com.airbnb.deeplinkdispatch.DeepLinkUri)1 DexClassLoader (dalvik.system.DexClassLoader)1