From 17d27d50c3111443c31ca427d04a7f6507ae5235 Mon Sep 17 00:00:00 2001 From: Andrei Solntsev Date: Fri, 19 Jul 2024 22:39:50 +0300 Subject: [PATCH] #340 fix warning "'throw' inside 'catch' block which ignores the caught exception" --- .../java/org/xhtmlrenderer/css/newmatch/Condition.java | 2 +- .../org/xhtmlrenderer/css/parser/CSSParseException.java | 7 +++++-- .../main/java/org/xhtmlrenderer/css/parser/CSSParser.java | 2 +- .../main/java/org/xhtmlrenderer/pdf/ITextFontResolver.java | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/newmatch/Condition.java b/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/newmatch/Condition.java index 31601c4d8..d8ee155ff 100644 --- a/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/newmatch/Condition.java +++ b/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/newmatch/Condition.java @@ -444,7 +444,7 @@ static NthChildCondition fromString(String number) { Matcher m = pattern.matcher(number); if (!m.matches()) { - throw new CSSParseException("Invalid nth-child selector: " + number, -1); + throw new CSSParseException("Invalid nth-child selector: " + number, -1, e); } else { int a = m.group(2).isEmpty() ? 1 : Integer.parseInt(m.group(2)); int b = (m.group(5) == null) ? 0 : Integer.parseInt(m.group(5)); diff --git a/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/parser/CSSParseException.java b/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/parser/CSSParseException.java index bc4445482..7d4e19ad3 100644 --- a/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/parser/CSSParseException.java +++ b/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/parser/CSSParseException.java @@ -20,8 +20,6 @@ package org.xhtmlrenderer.css.parser; public class CSSParseException extends RuntimeException { - private static final long serialVersionUID = 1L; - private final Token _found; private final Token[] _expected; private int _line; @@ -31,6 +29,11 @@ public class CSSParseException extends RuntimeException { private boolean _callerNotified; public CSSParseException(String message, int line) { + this(message, line, null); + } + + public CSSParseException(String message, int line, Throwable cause) { + super(message, cause); _found = null; _expected = null; _line = line; diff --git a/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/parser/CSSParser.java b/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/parser/CSSParser.java index 7da5cb45a..5835996e8 100644 --- a/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/parser/CSSParser.java +++ b/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/parser/CSSParser.java @@ -273,7 +273,7 @@ private void import_rule(Stylesheet stylesheet) throws IOException { System.out.println("Token: " + tokenValue + " resolved " + resolvedUri); info.setUri(resolvedUri); } catch (URISyntaxException use) { - throw new CSSParseException("Invalid URL, " + use.getMessage(), getCurrentLine()); + throw new CSSParseException("Invalid URL, " + use.getMessage(), getCurrentLine(), use); } } diff --git a/flying-saucer-pdf/src/main/java/org/xhtmlrenderer/pdf/ITextFontResolver.java b/flying-saucer-pdf/src/main/java/org/xhtmlrenderer/pdf/ITextFontResolver.java index fce57ca8b..456b390f9 100644 --- a/flying-saucer-pdf/src/main/java/org/xhtmlrenderer/pdf/ITextFontResolver.java +++ b/flying-saucer-pdf/src/main/java/org/xhtmlrenderer/pdf/ITextFontResolver.java @@ -467,7 +467,7 @@ private BaseFont createFont(String name, String encoding, boolean embedded) { return BaseFont.createFont(name, encoding, embedded); } catch (DocumentException | IOException e) { - throw new RuntimeException("Failed to load font " + name + " and encoding " + encoding); + throw new RuntimeException("Failed to load font " + name + " and encoding " + encoding, e); } }