Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch NumberFormatException in BibTeXML exporter #4698

Merged
merged 1 commit into from
Feb 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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