Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3477927d authored by Adam Lesinski's avatar Adam Lesinski
Browse files

ResourcesManager: Throw exception if failed to load asset path

Previously if we failed to load an asset path, we would return a
null AssetManager which would lead to an immediate NPE.

Throw a proper exception instead, detailing which path failed to load.

Bug:28216288
Change-Id: I491b9316b837bf333b5ae78d4eb1ee31741617ec
parent fdb26b90
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -224,7 +224,7 @@ public class ResourcesManager {
     * @return a new AssetManager.
    */
    @VisibleForTesting
    protected AssetManager createAssetManager(@NonNull final ResourcesKey key) {
    protected @NonNull AssetManager createAssetManager(@NonNull final ResourcesKey key) {
        AssetManager assets = new AssetManager();

        // resDir can be null if the 'android' package is creating a new Resources object.
@@ -232,14 +232,15 @@ public class ResourcesManager {
        // already.
        if (key.mResDir != null) {
            if (assets.addAssetPath(key.mResDir) == 0) {
                return null;
                throw new IllegalArgumentException("failed to add asset path " + key.mResDir);
            }
        }

        if (key.mSplitResDirs != null) {
            for (final String splitResDir : key.mSplitResDirs) {
                if (assets.addAssetPath(splitResDir) == 0) {
                    return null;
                    throw new IllegalArgumentException(
                            "failed to add split asset path " + splitResDir);
                }
            }
        }