AssetManager: fix open and openNonAsset not throwing exception on error

This commit is contained in:
Mis012
2024-05-27 14:01:43 +02:00
parent 71717edc58
commit 92bb75d19f
2 changed files with 5 additions and 1 deletions

View File

@@ -24,7 +24,7 @@ JNIEXPORT jlong JNICALL Java_android_content_res_AssetManager_openAsset(JNIEnv *
struct AssetManager *asset_manager = _PTR(_GET_LONG_FIELD(this, "mObject")); struct AssetManager *asset_manager = _PTR(_GET_LONG_FIELD(this, "mObject"));
struct Asset *asset = AssetManager_openNonAsset(asset_manager, file_name, mode); struct Asset *asset = AssetManager_openNonAsset(asset_manager, file_name, mode);
printf("AssetManager_openAsset(%p, %s, %d)\n", asset_manager, file_name, mode); printf("AssetManager_openAsset(%p, %s, %d) returns %p\n", asset_manager, file_name, mode, asset);
return _INTPTR(asset); return _INTPTR(asset);
} }

View File

@@ -311,6 +311,8 @@ public final class AssetManager {
*/ */
public final InputStream open(String fileName, int accessMode) throws IOException { public final InputStream open(String fileName, int accessMode) throws IOException {
long asset = openAsset("assets/" + fileName, accessMode); long asset = openAsset("assets/" + fileName, accessMode);
if(asset == 0)
throw new FileNotFoundException("file: " + fileName);
return new AssetInputStream(asset); return new AssetInputStream(asset);
} }
@@ -382,6 +384,8 @@ public final class AssetManager {
*/ */
public final InputStream openNonAsset(int cookie, String fileName, int accessMode) throws IOException { public final InputStream openNonAsset(int cookie, String fileName, int accessMode) throws IOException {
long asset = openAsset(fileName, accessMode); long asset = openAsset(fileName, accessMode);
if(asset == 0)
throw new FileNotFoundException("file: " + fileName);
return new AssetInputStream(asset); return new AssetInputStream(asset);
} }