diff --git a/src/main/java/org/jabref/logic/exporter/BibTeXMLExporter.java b/src/main/java/org/jabref/logic/exporter/BibTeXMLExporter.java index 01a74e9f855..363a67bca42 100644 --- a/src/main/java/org/jabref/logic/exporter/BibTeXMLExporter.java +++ b/src/main/java/org/jabref/logic/exporter/BibTeXMLExporter.java @@ -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. */ @@ -192,33 +192,37 @@ private void parseInbook(Inbook inbook, BibEntry bibEntry, Entry entry) { */ private void parse(T entryType, BibEntry bibEntry, Entry entry) { List declaredSetMethods = getListOfSetMethods(entryType); - Map fieldMap = bibEntry.getFieldMap(); - for (Map.Entry entryField : fieldMap.entrySet()) { - String value = entryField.getValue(); + for (Map.Entry 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); } }