add null checks

This commit is contained in:
Jörg Prante 2016-09-20 17:10:50 +02:00
parent a98816e315
commit 19f4d74d3e
2 changed files with 9 additions and 2 deletions

View file

@ -136,6 +136,9 @@ public class MarcField implements Comparable<MarcField> {
} }
public boolean isTagValid() { public boolean isTagValid() {
if (tag == null) {
return true;
}
return tag.length() == 3 return tag.length() == 3
&& ((tag.charAt(0) >= '0' && tag.charAt(0) <= '9') && ((tag.charAt(0) >= '0' && tag.charAt(0) <= '9')
|| (tag.charAt(0) >= 'A' && tag.charAt(0) <= 'Z')) || (tag.charAt(0) >= 'A' && tag.charAt(0) <= 'Z'))
@ -149,6 +152,9 @@ public class MarcField implements Comparable<MarcField> {
if (isControl()) { if (isControl()) {
return true; return true;
} }
if (indicator == null) {
return true;
}
boolean b = indicator.length() <= 9; boolean b = indicator.length() <= 9;
for (int i = 0; i < indicator.length(); i++) { for (int i = 0; i < indicator.length(); i++) {
b = indicator.charAt(i) == ' ' b = indicator.charAt(i) == ' '
@ -167,6 +173,9 @@ public class MarcField implements Comparable<MarcField> {
if (isControl()) { if (isControl()) {
return true; return true;
} }
if (subfieldIds == null) {
return true;
}
boolean b = true; boolean b = true;
for (int i = 0; i < subfieldIds.length(); i++) { for (int i = 0; i < subfieldIds.length(); i++) {
b = subfieldIds.charAt(i) == ' ' b = subfieldIds.charAt(i) == ' '

View file

@ -20,8 +20,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import org.junit.Test; import org.junit.Test;
import org.xbib.marc.Marc;
import org.xbib.marc.MarcXchangeConstants;
import org.xbib.marc.json.MarcJsonWriter; import org.xbib.marc.json.MarcJsonWriter;
import org.xbib.marc.xml.MarcXchangeWriter; import org.xbib.marc.xml.MarcXchangeWriter;