mp4parser icon indicating copy to clipboard operation
mp4parser copied to clipboard

NullPointerException when initializing IsoFile constructor on Android

Open JacobKant opened this issue 10 months ago • 1 comments

Description

When attempting to create an instance of IsoFile using the constructor IsoFile(sourceFile), a NullPointerException occurs while trying to close an InputStream in the PropertyBoxParserImpl initialization.

The issue appears to be related to resource loading in Android environment. Specifically, the following line in PropertyBoxParserImpl fails to load the properties file:

InputStream is = getClass().getResourceAsStream("/isoparser2-default.properties");

This method of resource loading might not work correctly on Android as Android handles resources differently from standard Java applications.

Environment

  • Platform: Android
  • Android API Level: 35 (Android 15)
  • Library versions:
    • org.mp4parser:isoparser:1.9.39
    • org.mp4parser:muxer:1.9.39

Stack Trace

java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.InputStream.close()' on a null object reference
    at org.mp4parser.PropertyBoxParserImpl.<init>(PropertyBoxParserImpl.java:77)
    at org.mp4parser.IsoFile.<init>(IsoFile.java:44)

Expected Behavior

The IsoFile constructor should successfully initialize with the provided source file.

Additional Information

The error occurs in the PropertyBoxParserImpl constructor when attempting to close an InputStream that appears to be null. The root cause seems to be that getResourceAsStream() returns null because it cannot locate the properties file in Android's resource system.

Possible Solution

The library might need to be modified to handle resource loading differently on Android platform, perhaps by:

  1. Including the properties file in a different location in the Android project
  2. Using Android's AssetManager to load the resource
  3. Providing an alternative way to initialize the properties

Question

Can the library maintainers confirm if this is a known issue with Android compatibility? Are there any workarounds available for Android implementations?

JacobKant avatar Mar 25 '25 09:03 JacobKant

Hey ! I had the same issue. The "quick-fix" for me was to remove .properties files from excluded resources in android build logic. Maybe you had the same

thalkz avatar May 16 '25 14:05 thalkz