New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExceptionInInitializerError #35

Open
zengjingfang opened this Issue Jun 5, 2018 · 2 comments

Comments

1 participant
@zengjingfang
Owner

zengjingfang commented Jun 5, 2018

java.lang.ExceptionInInitializerError
at com.xtc.im.phone.thirdpush.c$1.onSuccess(Unknown Source)
at com.umeng.message.UmengMessageCallbackHandlerService.onHandleIntent(Unknown Source)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
Caused by: java.lang.RuntimeException: android.os.DeadObjectException
at android.os.storage.StorageManager.getVolumeList(StorageManager.java:886)
at android.os.Environment$UserEnvironment.getExternalDirs(Environment.java:103)
at android.os.Environment.getExternalStorageDirectory(Environment.java:360)
at com.xtc.im.core.push.store.SDCardFile.(Unknown Source)
... 6 more
Caused by: android.os.DeadObjectException
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:503)
at android.content.pm.IPackageManager$Stub$Proxy.getPackageUid(IPackageManager.java:2235)
at android.os.storage.StorageManager.getVolumeList(StorageManager.java:880)
... 9 more
java.lang.RuntimeException: android.os.DeadObjectException
at android.os.storage.StorageManager.getVolumeList(StorageManager.java:886)
at android.os.Environment$UserEnvironment.getExternalDirs(Environment.java:103)
at android.os.Environment.getExternalStorageDirectory(Environment.java:360)
at com.xtc.im.core.push.store.SDCardFile.(Unknown Source)
at com.xtc.im.phone.thirdpush.c$1.onSuccess(Unknown Source)
at com.umeng.message.UmengMessageCallbackHandlerService.onHandleIntent(Unknown Source)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
Caused by: android.os.DeadObjectException
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:503)
at android.content.pm.IPackageManager$Stub$Proxy.getPackageUid(IPackageManager.java:2235)
at android.os.storage.StorageManager.getVolumeList(StorageManager.java:880)
... 9 more
android.os.DeadObjectException
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:503)
at android.content.pm.IPackageManager$Stub$Proxy.getPackageUid(IPackageManager.java:2235)
at android.os.storage.StorageManager.getVolumeList(StorageManager.java:880)
at android.os.Environment$UserEnvironment.getExternalDirs(Environment.java:103)
at android.os.Environment.getExternalStorageDirectory(Environment.java:360)
at com.xtc.im.core.push.store.SDCardFile.(Unknown Source)
at com.xtc.im.phone.thirdpush.c$1.onSuccess(Unknown Source)
at com.umeng.message.UmengMessageCallbackHandlerService.onHandleIntent(Unknown Source)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)

image

image

@zengjingfang zengjingfang self-assigned this Jun 5, 2018

@zengjingfang

This comment has been minimized.

Owner

zengjingfang commented Jun 5, 2018

源码追踪

    public static File getExternalStorageDirectory() {
        throwIfUserRequired();
        return sCurrentUser.getExternalDirs()[0];
    }

public File[] getExternalDirs() {
            final StorageVolume[] volumes = StorageManager.getVolumeList(mUserId,
                    StorageManager.FLAG_FOR_WRITE);
            final File[] files = new File[volumes.length];
            for (int i = 0; i < volumes.length; i++) {
                files[i] = volumes[i].getPathFile();
            }
            return files;
        }

public static @NonNull StorageVolume[] getVolumeList(int userId, int flags) {
        final IStorageManager storageManager = IStorageManager.Stub.asInterface(
                ServiceManager.getService("mount"));
        try {
            String packageName = ActivityThread.currentOpPackageName();
            if (packageName == null) {
                // Package name can be null if the activity thread is running but the app
                // hasn't bound yet. In this case we fall back to the first package in the
                // current UID. This works for runtime permissions as permission state is
                // per UID and permission realted app ops are updated for all UID packages.
                String[] packageNames = ActivityThread.getPackageManager().getPackagesForUid(
                        android.os.Process.myUid());
                if (packageNames == null || packageNames.length <= 0) {
                    return new StorageVolume[0];
                }
                packageName = packageNames[0];
            }
            final int uid = ActivityThread.getPackageManager().getPackageUid(packageName,
                    PackageManager.MATCH_DEBUG_TRIAGED_MISSING, userId);
            if (uid <= 0) {
                return new StorageVolume[0];
            }
            return storageManager.getVolumeList(uid, packageName, flags);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
@zengjingfang

This comment has been minimized.

Owner

zengjingfang commented Jun 5, 2018

原因

静态变量初始化时出现异常则会抛出ExceptionInInitializerError,这个是因为getExternalStorageDirectory内部抛出了异常DeadObjectException,从而导致抛出ExceptionInInitializerError。

private static final String SDCARD_DIR = Environment.getExternalStorageDirectory().getPath() + "/im/";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment