Skip to content

Commit

Permalink
Catch NumberFormatException in BibTeXML exporter (#4698)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasdiez authored and Siedlerchr committed Feb 24, 2019
1 parent 4deb581 commit 395609d
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/main/java/org/jabref/logic/exporter/BibTeXMLExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private void createMarshallerAndWriteToFile(File file, Path resultFile) throws S
}

/**
* Contains same logic as the {@link parse()} method, but inbook needs a special treatment, because
* Contains same logic as the {@link #parse(Object, BibEntry, Entry)} method, but inbook needs a special treatment, because
* the contents of inbook are stored in a List of JAXBElements. So we first need to create
* a JAXBElement for every field and then add it to the content list.
*/
Expand Down Expand Up @@ -192,33 +192,37 @@ private void parseInbook(Inbook inbook, BibEntry bibEntry, Entry entry) {
*/
private <T> void parse(T entryType, BibEntry bibEntry, Entry entry) {
List<Method> declaredSetMethods = getListOfSetMethods(entryType);
Map<String, String> fieldMap = bibEntry.getFieldMap();
for (Map.Entry<String, String> entryField : fieldMap.entrySet()) {
String value = entryField.getValue();
for (Map.Entry<String, String> entryField : bibEntry.getFieldMap().entrySet()) {
String key = entryField.getKey();
String value = entryField.getValue();
for (Method method : declaredSetMethods) {
String methodNameWithoutSet = method.getName().replace("set", "").toLowerCase(ENGLISH);
try {
if (!methodNameWithoutSet.equals(key)) {
continue;
}

if ("year".equals(key) && key.equals(methodNameWithoutSet)) {
try {
if ("year".equals(key)) {
try {

XMLGregorianCalendar calendar = DatatypeFactory.newInstance()
.newXMLGregorianCalendar(value);
XMLGregorianCalendar calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(value);
method.invoke(entryType, calendar);
} catch (DatatypeConfigurationException e) {
LOGGER.error("A configuration error occured");
}
break;
} else if ("number".equals(key) && key.equals(methodNameWithoutSet)) {
method.invoke(entryType, new BigInteger(value));
} else if ("number".equals(key)) {
try {
method.invoke(entryType, new BigInteger(value));
} catch (NumberFormatException exception) {
LOGGER.warn("The value %s of the 'number' field is not an integer and thus is ignored for the export", value);
}
break;
} else if (key.equals(methodNameWithoutSet)) {
} else {
method.invoke(entryType, value);
break;
}
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
LOGGER.error("Could not invoke method", e);
LOGGER.error("Could not invoke method " + method.getName(), e);
}
}

Expand Down

0 comments on commit 395609d

Please sign in to comment.