zhipingwei / android-daisy-epub-reader

Automatically exported from code.google.com/p/android-daisy-epub-reader
0 stars 0 forks source link

NPE when trying to extract the text from parts that don't have a text element #55

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
getText() in Daisy202Snippet.java can throw a null pointer exception (NPE). 

The code tries to dereference an object that may not exist, as follows:
doc.getElementById(id).text();

We need to check getElementById() is not null before calling the .text() method.

What steps will reproduce the problem?
1. Call ProcessExternalSmilFile with the following file 
/sdcard/files-used-for-testing/testfiles/minidaisyaudiobook/mdab0001.smil

What is the expected output? 

The code should handle the situation more gracefully, ideally in a way that 
enables the user to realise where the problem stems from so they can take 
appropriate steps (e.g. to contact the supplier of the book and report the 
problem with the book).

What do you see instead?
A null pointer exception.

I've attached the files that trigger the problem. They are also in source 
control for this project.

Original issue reported on code.google.com by julianharty on 19 Feb 2012 at 2:13

Attachments:

GoogleCodeExporter commented 8 years ago
http://code.google.com/p/android-daisy-epub-reader/source/detail?r=437 has a 
test that reproduces the problem reliably.
http://code.google.com/p/android-daisy-epub-reader/source/detail?r=438 fixes 
the incorrect link in one of the test books. Now we have a reliable, failing 
test, we can rely on the test rather than on this broken file :)

The next step is to decide how to report parsing and contents errors.

Original comment by julianharty on 19 Feb 2012 at 2:38