Fixed NPE case when on audio resource parsed with null tag

pull/167/head
luccioman 7 years ago
parent c3ff50c17a
commit fb6457f5bc

@ -250,47 +250,63 @@ public class audioTagParser extends AbstractParser implements Parser {
f = AudioFileIO.read(tempFile); f = AudioFileIO.read(tempFile);
} }
Tag tag = f.getTag(); final Tag tag = f.getTag();
final Set<String> lang = new HashSet<String>(); final Set<String> lang = new HashSet<String>();
lang.add(tag.getFirst(FieldKey.LANGUAGE)); if(tag != null) {
lang.add(tag.getFirst(FieldKey.LANGUAGE));
}
// title // title
final List<String> titles = new ArrayList<String>(); final List<String> titles = new ArrayList<String>();
titles.add(tag.getFirst(FieldKey.TITLE)); if(tag != null) {
titles.add(tag.getFirst(FieldKey.ALBUM)); titles.add(tag.getFirst(FieldKey.TITLE));
titles.add(tag.getFirst(FieldKey.ALBUM));
}
titles.add(filename); titles.add(filename);
// text // text
final List<String> descriptions = new ArrayList<String>(7); final List<String> descriptions = new ArrayList<String>(7);
final StringBuilder text = new StringBuilder(500); final StringBuilder text = new StringBuilder(500);
final char space = ' '; final char space = ' ';
String field = tag.getFirst(FieldKey.ARTIST); if(tag != null) {
descriptions.add(FieldKey.ARTIST.name() + ": " + field); String field = tag.getFirst(FieldKey.ARTIST);
text.append(field); text.append(space); descriptions.add(FieldKey.ARTIST.name() + ": " + field);
field = tag.getFirst(FieldKey.ALBUM); text.append(field); text.append(space);
descriptions.add(FieldKey.ALBUM.name() + ": " + field);
text.append(field); text.append(space); field = tag.getFirst(FieldKey.ALBUM);
field = tag.getFirst(FieldKey.TITLE); descriptions.add(FieldKey.ALBUM.name() + ": " + field);
descriptions.add(FieldKey.TITLE.name() + ": " + field); text.append(field); text.append(space);
text.append(field); text.append(space);
field = tag.getFirst(FieldKey.COMMENT); field = tag.getFirst(FieldKey.TITLE);
descriptions.add(FieldKey.COMMENT.name() + ": " + field); descriptions.add(FieldKey.TITLE.name() + ": " + field);
text.append(field); text.append(space); text.append(field); text.append(space);
field = tag.getFirst(FieldKey.LYRICS);
descriptions.add(FieldKey.LYRICS.name() + ": " + field); field = tag.getFirst(FieldKey.COMMENT);
text.append(field); text.append(space); descriptions.add(FieldKey.COMMENT.name() + ": " + field);
field = tag.getFirst(FieldKey.TAGS); text.append(field); text.append(space);
descriptions.add(FieldKey.TAGS.name() + ": " + field);
text.append(field); text.append(space); field = tag.getFirst(FieldKey.LYRICS);
field = tag.getFirst(FieldKey.GENRE); descriptions.add(FieldKey.LYRICS.name() + ": " + field);
descriptions.add(FieldKey.GENRE.name() + ": " + field); text.append(field); text.append(space);
text.append(field); text.append(space);
field = tag.getFirst(FieldKey.TAGS);
descriptions.add(FieldKey.TAGS.name() + ": " + field);
text.append(field); text.append(space);
field = tag.getFirst(FieldKey.GENRE);
descriptions.add(FieldKey.GENRE.name() + ": " + field);
text.append(field); text.append(space);
}
text.append(location.toTokens()); text.append(location.toTokens());
// dc:subject // dc:subject
final String[] subject = new String[1]; final String[] subject;
subject[0] = tag.getFirst(FieldKey.GENRE); if(tag != null) {
subject = new String[] {tag.getFirst(FieldKey.GENRE)};
} else {
subject = new String[0];
}
/* normalize to a single Media Type. Advantages : /* normalize to a single Media Type. Advantages :
* - index document with the right media type when HTTP response header "Content-Type" is missing or has a wrong value * - index document with the right media type when HTTP response header "Content-Type" is missing or has a wrong value
@ -312,7 +328,7 @@ public class audioTagParser extends AbstractParser implements Parser {
lang, // languages lang, // languages
subject, // keywords, dc:subject subject, // keywords, dc:subject
titles, // title titles, // title
tag.getFirst(FieldKey.ARTIST), // author tag != null ? tag.getFirst(FieldKey.ARTIST) : null, // author
location.getHost(), // publisher location.getHost(), // publisher
null, // sections null, // sections
descriptions, // abstrct descriptions, // abstrct

Loading…
Cancel
Save