From d5bbd9c0ec07ec2cf1c8d581fbe4e19f93937446 Mon Sep 17 00:00:00 2001 From: Andreas Buchen Date: Tue, 3 Dec 2024 23:59:29 +0530 Subject: [PATCH] Fix PDF parser swallows error message about duplicate securities (#4383) Co-authored-by: Alexander Ott <45203494+Nirus2000@users.noreply.github.com> --- .../datatransfer/DuplicateSecurityException.java | 11 +++++++++++ .../abuchen/portfolio/datatransfer/SecurityCache.java | 2 +- .../abuchen/portfolio/datatransfer/pdf/PDFParser.java | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/DuplicateSecurityException.java diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/DuplicateSecurityException.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/DuplicateSecurityException.java new file mode 100644 index 0000000000..a26a15f7a4 --- /dev/null +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/DuplicateSecurityException.java @@ -0,0 +1,11 @@ +package name.abuchen.portfolio.datatransfer; + +public class DuplicateSecurityException extends IllegalArgumentException +{ + private static final long serialVersionUID = 1L; + + public DuplicateSecurityException(String s) + { + super(s); + } +} diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/SecurityCache.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/SecurityCache.java index 4b2bb5fe83..f72026e29e 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/SecurityCache.java +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/SecurityCache.java @@ -86,7 +86,7 @@ public Security lookup(String isin, String tickerSymbol, String wkn, String name // message is only returned to the user if the other attributes also did // not match if (idOfAttributeWithDuplicateSecurities >= 0) - throw new IllegalArgumentException(MessageFormat.format(MESSAGES.get(idOfAttributeWithDuplicateSecurities), + throw new DuplicateSecurityException(MessageFormat.format(MESSAGES.get(idOfAttributeWithDuplicateSecurities), attributes.get(idOfAttributeWithDuplicateSecurities))); // second: check the name. But: even if the name matches, we also must diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/pdf/PDFParser.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/pdf/PDFParser.java index d5b74fc703..db199eab11 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/pdf/PDFParser.java +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/pdf/PDFParser.java @@ -22,6 +22,7 @@ import name.abuchen.portfolio.Messages; import name.abuchen.portfolio.datatransfer.DocumentContext; +import name.abuchen.portfolio.datatransfer.DuplicateSecurityException; import name.abuchen.portfolio.datatransfer.Extractor.Item; import name.abuchen.portfolio.datatransfer.ImportAction; import name.abuchen.portfolio.datatransfer.ImportAction.Context; @@ -366,6 +367,10 @@ public void parse(String filename, DocumentContext documentContext, String[] lin // if parsing was successful, then return return; } + catch (DuplicateSecurityException e) + { + throw e; + } catch (IllegalArgumentException ignore) { // try next sub-section