NullPointerException when committing changes

Issue #188 invalid
fillobotto created an issue

I'd like to report an occasional issue I have when executing [AudioFile].commit() method on Android devices. The report comes from Analytics so I couldn't reproduce it. If you need more information, please let me know, thanks.

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.io.File.getAbsolutePath()' on a null object reference at 
org.jaudiotagger.audio.generic.AudioFileWriter.delete(SourceFile:200) at 
org.jaudiotagger.audio.generic.AudioFileWriter.precheckWrite(SourceFile:275) at 
org.jaudiotagger.audio.generic.AudioFileWriter.write(SourceFile:317) at 
org.jaudiotagger.audio.AudioFileIO.writeFile(SourceFile:482) at 
org.jaudiotagger.audio.AudioFileIO.write(SourceFile:208) at 
org.jaudiotagger.audio.AudioFile.commit(SourceFile:124) 

Comments (14)

  1. fillobotto reporter

    Commit method takes no parameters. If you mean in tag fields that's not possible since I'm explicitly checking for nulls before using setField method.

  2. fillobotto reporter

    This is the only method through I set fields.

    public void setField(FieldKey key, String value) {
            if (value != null && !value.equalsIgnoreCase(FrameBodyCOMM.DEFAULT)) {
                if ((key == FieldKey.TRACK || key == FieldKey.TRACK_TOTAL || key == FieldKey.DISC_NO || key == FieldKey.DISC_TOTAL) && (value.equalsIgnoreCase(FrameBodyCOMM.DEFAULT) || value.equalsIgnoreCase("null"))) {
                    value = "0";
                }
                for (Tag tag : this.audioFileList.values()) {
                    try {
                        tag.setField(key, value);
                    } catch (FieldDataInvalidException exception) {
                        exception.printStackTrace();
                    }
                }
            }
        }
    
  3. IJabz repo owner

    This isnt the code that calls the commit,the error loooks like the underlying filename of the audio file is null rather than the fields being null

  4. fillobotto reporter

    I just use this line for reading and it's inside a try catch so any error related to the file should be caught such as InvalidAudioFrameException.

     AudioFile audio = AudioFileIO.read(new File(path));
    

    Regarding the commit, I'm just calling it as described in documentation

    for (final AudioFile audioFile : this.audioFileList.keySet()) {
         audioFile.commit();
    }
    
  5. fillobotto reporter

    I forgot to mention that I'm using 2.2.6 snapshot source, edited so it uses java.noi.Charset instead of java.noi.StandardCharsets

  6. IJabz repo owner

    I dont use Android and dont understand this virtual method error I think the best thing would be to post this question on stackoverflow to make progress with this.

  7. fillobotto reporter

    getAbsolutePath() is just the Android equivalent of getPath() and it is being executed inside AudioFileWriter.delete() when doing [AudioFile].getFile().getPath() but for some reason getFile() returns null. I don't see how calling just commit() should be an error in user code.

  8. IJabz repo owner

    Well we can argue about that but the point is I dont know what is causing the issue, therefore I cant currentiy fix it

  9. fillobotto reporter

    Ok then, I'll try to add some logging in next app releases so I'll see if I can find some clue with it

  10. Log in to comment