From 8d3bd936a74d759a686e1a37dea40959729f4577 Mon Sep 17 00:00:00 2001 From: Damien Hunter Date: Sun, 4 Feb 2024 18:02:51 +0000 Subject: [PATCH 1/4] modified: src/main/java/org/jsoup/select/StructuralEvaluator.java --- .../org/jsoup/select/StructuralEvaluator.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/jsoup/select/StructuralEvaluator.java b/src/main/java/org/jsoup/select/StructuralEvaluator.java index ca7beacb15..8d186793d2 100644 --- a/src/main/java/org/jsoup/select/StructuralEvaluator.java +++ b/src/main/java/org/jsoup/select/StructuralEvaluator.java @@ -12,19 +12,19 @@ /** * Base structural evaluator. */ -abstract class StructuralEvaluator extends Evaluator { +public abstract class StructuralEvaluator extends Evaluator { final Evaluator evaluator; - public StructuralEvaluator(Evaluator evaluator) { + StructuralEvaluator(Evaluator evaluator) { this.evaluator = evaluator; } // Memoize inner matches, to save repeated re-evaluations of parent, sibling etc. // root + element: Boolean matches. ThreadLocal in case the Evaluator is compiled then reused across multi threads - final ThreadLocal>> + public final ThreadLocal>> threadMemo = ThreadLocal.withInitial(IdentityHashMap::new); - boolean memoMatches(final Element root, final Element element) { + public boolean memoMatches(final Element root, final Element element) { Map> rootMemo = threadMemo.get(); Map memo = rootMemo.computeIfAbsent(root, Functions.identityMapFunction()); return memo.computeIfAbsent(element, key -> evaluator.matches(root, key)); @@ -35,7 +35,7 @@ boolean memoMatches(final Element root, final Element element) { super.reset(); } - static class Root extends Evaluator { + public static class Root extends Evaluator { @Override public boolean matches(Element root, Element element) { return root == element; @@ -50,7 +50,7 @@ public boolean matches(Element root, Element element) { } } - static class Has extends StructuralEvaluator { + public static class Has extends StructuralEvaluator { static final ThreadLocal> ThreadElementIter = ThreadLocal.withInitial(() -> new NodeIterator<>(new Element("html"), Element.class)); // the element here is just a placeholder so this can be final - gets set in restart() @@ -84,7 +84,7 @@ public String toString() { } /** Implements the :is(sub-query) pseudo-selector */ - static class Is extends StructuralEvaluator { + public static class Is extends StructuralEvaluator { public Is(Evaluator evaluator) { super(evaluator); } @@ -104,7 +104,7 @@ public String toString() { } } - static class Not extends StructuralEvaluator { + public static class Not extends StructuralEvaluator { public Not(Evaluator evaluator) { super(evaluator); } @@ -124,7 +124,7 @@ public String toString() { } } - static class Parent extends StructuralEvaluator { + public static class Parent extends StructuralEvaluator { public Parent(Evaluator evaluator) { super(evaluator); } @@ -159,7 +159,7 @@ public String toString() { Holds a list of evaluators for one > two > three immediate parent matches, and the final direct evaluator under test. To match, these are effectively ANDed together, starting from the last, matching up to the first. */ - static class ImmediateParentRun extends Evaluator { + public static class ImmediateParentRun extends Evaluator { final ArrayList evaluators = new ArrayList<>(); int cost = 2; @@ -199,7 +199,7 @@ public String toString() { } } - static class PreviousSibling extends StructuralEvaluator { + public static class PreviousSibling extends StructuralEvaluator { public PreviousSibling(Evaluator evaluator) { super(evaluator); } @@ -228,7 +228,7 @@ public String toString() { } } - static class ImmediatePreviousSibling extends StructuralEvaluator { + public static class ImmediatePreviousSibling extends StructuralEvaluator { public ImmediatePreviousSibling(Evaluator evaluator) { super(evaluator); } From 895ca0be0d8225695a10f7854a2f3dba23f63d2f Mon Sep 17 00:00:00 2001 From: Damien Hunter Date: Sun, 4 Feb 2024 18:21:21 +0000 Subject: [PATCH 2/4] modified: src/main/java/org/jsoup/parser/StreamParser.java --- src/main/java/org/jsoup/parser/StreamParser.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jsoup/parser/StreamParser.java b/src/main/java/org/jsoup/parser/StreamParser.java index ba0078f8ad..6d4d5f3a25 100644 --- a/src/main/java/org/jsoup/parser/StreamParser.java +++ b/src/main/java/org/jsoup/parser/StreamParser.java @@ -51,9 +51,9 @@ interface to the document and its elements.

@since 1.18.1 */ public class StreamParser implements Closeable { - final private Parser parser; - final private TreeBuilder treeBuilder; - final private ElementIterator it = new ElementIterator(); + private final Parser parser; + private final TreeBuilder treeBuilder; + private final ElementIterator it = new ElementIterator(); @Nullable private Document document; private boolean stopped = false; @@ -294,7 +294,7 @@ public Element expectNext(String query) throws IOException { final class ElementIterator implements Iterator, NodeVisitor { // listeners add to a next emit queue, as a single token read step may yield multiple elements - final private Queue emitQueue = new LinkedList<>(); + private final Queue emitQueue = new LinkedList<>(); private @Nullable Element current; // most recently emitted private @Nullable Element next; // element waiting to be picked up private @Nullable Element tail; // The last tailed element (), on hold for final pop @@ -375,7 +375,4 @@ private void maybeFindNext() { } } } -} - - - +} \ No newline at end of file From 3825603c46e355832a4afb0ad61914dd4130067e Mon Sep 17 00:00:00 2001 From: Damien Hunter Date: Tue, 6 Feb 2024 11:54:38 +0000 Subject: [PATCH 3/4] modified: src/main/java/org/jsoup/parser/TreeBuilder.java --- src/main/java/org/jsoup/parser/TreeBuilder.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jsoup/parser/TreeBuilder.java b/src/main/java/org/jsoup/parser/TreeBuilder.java index fb5c0708fa..2287be1226 100644 --- a/src/main/java/org/jsoup/parser/TreeBuilder.java +++ b/src/main/java/org/jsoup/parser/TreeBuilder.java @@ -101,7 +101,7 @@ void nodeListener(NodeVisitor nodeListener) { abstract TreeBuilder newInstance(); void runParser() { - do {} while (stepParser()); // run until stepParser sees EOF + do {/* Place holder comment. Internal loop like a while true. */} while (stepParser()); // run until stepParser sees EOF completeParse(); } @@ -183,7 +183,7 @@ Element currentElement() { @return true if there is a current element on the stack, and its name equals the supplied */ boolean currentElementIs(String normalName) { - if (stack.size() == 0) + if (stack.isEmpty()) return false; Element current = currentElement(); return current != null && current.normalName().equals(normalName) @@ -197,7 +197,7 @@ boolean currentElementIs(String normalName) { @return true if there is a current element on the stack, and its name equals the supplied */ boolean currentElementIs(String normalName, String namespace) { - if (stack.size() == 0) + if (stack.isEmpty()) return false; Element current = currentElement(); return current != null && current.normalName().equals(normalName) From 4807192d1fc263c6b1b442cd75a11ab3f478f5ca Mon Sep 17 00:00:00 2001 From: Damien Hunter Date: Fri, 8 Mar 2024 21:29:40 +0000 Subject: [PATCH 4/4] modified: src/main/java/org/jsoup/Connection.java modified: src/main/java/org/jsoup/HttpStatusException.java modified: src/main/java/org/jsoup/SerializationException.java modified: src/main/java/org/jsoup/UncheckedIOException.java modified: src/main/java/org/jsoup/UnsupportedMimeTypeException.java modified: src/main/java/org/jsoup/helper/ChangeNotifyingArrayList.java modified: src/main/java/org/jsoup/helper/CookieUtil.java modified: src/main/java/org/jsoup/helper/DataUtil.java modified: src/main/java/org/jsoup/helper/HttpConnection.java modified: src/main/java/org/jsoup/helper/UrlBuilder.java modified: src/main/java/org/jsoup/helper/ValidationException.java modified: src/main/java/org/jsoup/helper/W3CDom.java modified: src/main/java/org/jsoup/internal/ControllableInputStream.java modified: src/main/java/org/jsoup/parser/CharacterReader.java modified: src/main/java/org/jsoup/select/Elements.java modified: src/main/java/org/jsoup/select/Selector.java modified: src/test/java/org/jsoup/parser/StreamParserTest.java --- src/main/java/org/jsoup/Connection.java | 4 --- .../java/org/jsoup/HttpStatusException.java | 3 ++- .../org/jsoup/SerializationException.java | 1 + .../java/org/jsoup/UncheckedIOException.java | 5 ++-- .../jsoup/UnsupportedMimeTypeException.java | 1 + .../helper/ChangeNotifyingArrayList.java | 6 ++--- .../java/org/jsoup/helper/CookieUtil.java | 5 ++-- src/main/java/org/jsoup/helper/DataUtil.java | 27 ++++++++++--------- .../java/org/jsoup/helper/HttpConnection.java | 16 +++++------ .../java/org/jsoup/helper/UrlBuilder.java | 7 +++-- .../org/jsoup/helper/ValidationException.java | 3 ++- src/main/java/org/jsoup/helper/W3CDom.java | 12 ++++----- .../internal/ControllableInputStream.java | 5 +--- .../org/jsoup/parser/CharacterReader.java | 2 +- src/main/java/org/jsoup/select/Elements.java | 7 ++--- src/main/java/org/jsoup/select/Selector.java | 3 ++- .../org/jsoup/parser/StreamParserTest.java | 6 +++-- 17 files changed, 57 insertions(+), 56 deletions(-) diff --git a/src/main/java/org/jsoup/Connection.java b/src/main/java/org/jsoup/Connection.java index 883844ebe8..d1e6c4cdce 100644 --- a/src/main/java/org/jsoup/Connection.java +++ b/src/main/java/org/jsoup/Connection.java @@ -40,9 +40,7 @@ the lifetime of the Connection object. A socket connection is only made at the p

For multi-threaded implementations, it is important to use a {@link #newRequest()} for each request. The session may be shared across concurrent threads, but a not a specific request.

*/ -@SuppressWarnings("unused") public interface Connection { - /** * GET and POST http methods. */ @@ -470,7 +468,6 @@ default Connection auth(@Nullable RequestAuthenticator authenticator) { * Common methods for Requests and Responses * @param Type of Base, either Request or Response */ - @SuppressWarnings("UnusedReturnValue") interface Base> { /** * Get the URL of this Request or Response. For redirected responses, this will be the final destination URL. @@ -623,7 +620,6 @@ interface Base> { /** * Represents a HTTP request. */ - @SuppressWarnings("UnusedReturnValue") interface Request extends Base { /** * Get the proxy used for this request. diff --git a/src/main/java/org/jsoup/HttpStatusException.java b/src/main/java/org/jsoup/HttpStatusException.java index 3e98aa63e3..d29ffb0c94 100644 --- a/src/main/java/org/jsoup/HttpStatusException.java +++ b/src/main/java/org/jsoup/HttpStatusException.java @@ -5,6 +5,7 @@ /** * Signals that a HTTP request resulted in a not OK HTTP response. */ +@SuppressWarnings("serial") public class HttpStatusException extends IOException { private final int statusCode; private final String url; @@ -22,4 +23,4 @@ public int getStatusCode() { public String getUrl() { return url; } -} +} \ No newline at end of file diff --git a/src/main/java/org/jsoup/SerializationException.java b/src/main/java/org/jsoup/SerializationException.java index ea188c90e0..0c7ddcdbc9 100644 --- a/src/main/java/org/jsoup/SerializationException.java +++ b/src/main/java/org/jsoup/SerializationException.java @@ -4,6 +4,7 @@ * A SerializationException is raised whenever serialization of a DOM element fails. This exception usually wraps an * {@link java.io.IOException} that may be thrown due to an inaccessible output stream. */ +@SuppressWarnings("serial") public final class SerializationException extends RuntimeException { /** * Creates and initializes a new serialization exception with no error message and cause. diff --git a/src/main/java/org/jsoup/UncheckedIOException.java b/src/main/java/org/jsoup/UncheckedIOException.java index a3b4fa31b6..4a92bcfa95 100644 --- a/src/main/java/org/jsoup/UncheckedIOException.java +++ b/src/main/java/org/jsoup/UncheckedIOException.java @@ -6,7 +6,8 @@ * @deprecated Use {@link java.io.UncheckedIOException} instead. This class acted as a compatibility shim for Java * versions prior to 1.8. */ -@Deprecated +@SuppressWarnings("serial") +@Deprecated (forRemoval = true) public class UncheckedIOException extends java.io.UncheckedIOException { public UncheckedIOException(IOException cause) { super(cause); @@ -19,4 +20,4 @@ public UncheckedIOException(String message) { public IOException ioException() { return getCause(); } -} +} \ No newline at end of file diff --git a/src/main/java/org/jsoup/UnsupportedMimeTypeException.java b/src/main/java/org/jsoup/UnsupportedMimeTypeException.java index 40fbc87031..779833724c 100644 --- a/src/main/java/org/jsoup/UnsupportedMimeTypeException.java +++ b/src/main/java/org/jsoup/UnsupportedMimeTypeException.java @@ -5,6 +5,7 @@ /** * Signals that a HTTP response returned a mime type that is not supported. */ +@SuppressWarnings("serial") public class UnsupportedMimeTypeException extends IOException { private final String mimeType; private final String url; diff --git a/src/main/java/org/jsoup/helper/ChangeNotifyingArrayList.java b/src/main/java/org/jsoup/helper/ChangeNotifyingArrayList.java index 67ac78d3e3..567b255dea 100644 --- a/src/main/java/org/jsoup/helper/ChangeNotifyingArrayList.java +++ b/src/main/java/org/jsoup/helper/ChangeNotifyingArrayList.java @@ -6,8 +6,9 @@ /** * Implementation of ArrayList that watches out for changes to the contents. */ +@SuppressWarnings("serial") public abstract class ChangeNotifyingArrayList extends ArrayList { - public ChangeNotifyingArrayList(int initialCapacity) { + protected ChangeNotifyingArrayList(int initialCapacity) { super(initialCapacity); } @@ -78,5 +79,4 @@ public boolean retainAll(Collection c) { onContentsChanged(); return super.retainAll(c); } - -} +} \ No newline at end of file diff --git a/src/main/java/org/jsoup/helper/CookieUtil.java b/src/main/java/org/jsoup/helper/CookieUtil.java index f375003753..0ccaf27a21 100644 --- a/src/main/java/org/jsoup/helper/CookieUtil.java +++ b/src/main/java/org/jsoup/helper/CookieUtil.java @@ -42,7 +42,7 @@ static void applyCookiesToRequest(HttpConnection.Request req, HttpURLConnection for (Map.Entry> entry : storedCookies.entrySet()) { // might be Cookie: name=value; name=value\nCookie2: name=value; name=value List cookies = entry.getValue(); // these will be name=val - if (cookies == null || cookies.size() == 0) // the cookie store often returns just an empty "Cookie" key, no val + if (cookies == null || cookies.isEmpty()) // the cookie store often returns just an empty "Cookie" key, no val continue; String key = entry.getKey(); // Cookie or Cookie2 @@ -85,6 +85,5 @@ static URI asUri(URL url) throws IOException { static void storeCookies(HttpConnection.Request req, URL url, Map> resHeaders) throws IOException { req.cookieManager().put(CookieUtil.asUri(url), resHeaders); // stores cookies for session - } -} +} \ No newline at end of file diff --git a/src/main/java/org/jsoup/helper/DataUtil.java b/src/main/java/org/jsoup/helper/DataUtil.java index 9664d3eac1..af93416530 100644 --- a/src/main/java/org/jsoup/helper/DataUtil.java +++ b/src/main/java/org/jsoup/helper/DataUtil.java @@ -44,7 +44,6 @@ * Internal static utilities for handling data. * */ -@SuppressWarnings("CharsetObjectCanBeUsed") public final class DataUtil { private static final Pattern charsetPattern = Pattern.compile("(?i)\\bcharset=\\s*(?:[\"'])?([^\\s,;\"']*)"); public static final Charset UTF_8 = Charset.forName("UTF-8"); // Don't use StandardCharsets, as those only appear in Android API 19, and we target 10. @@ -140,14 +139,15 @@ public static Document load(Path path, @Nullable String charsetName, String base * @see Connection.Response#streamParser() */ public static StreamParser streamParser(Path path, @Nullable Charset charset, String baseUri, Parser parser) throws IOException { - StreamParser streamer = new StreamParser(parser); - String charsetName = charset != null? charset.name() : null; - DataUtil.CharsetDoc charsetDoc = DataUtil.detectCharset(openStream(path), charsetName, baseUri, parser); - BufferedReader reader = new BufferedReader(new InputStreamReader(charsetDoc.input, charsetDoc.charset), DefaultBufferSize); - maybeSkipBom(reader, charsetDoc); - streamer.parse(reader, baseUri); // initializes the parse and the document, but does not step() it - - return streamer; + try(StreamParser streamer = new StreamParser(parser);){ + String charsetName = charset != null? charset.name() : null; + DataUtil.CharsetDoc charsetDoc = DataUtil.detectCharset(openStream(path), charsetName, baseUri, parser); + BufferedReader reader = new BufferedReader(new InputStreamReader(charsetDoc.input, charsetDoc.charset), DefaultBufferSize); + maybeSkipBom(reader, charsetDoc); + streamer.parse(reader, baseUri); // initializes the parse and the document, but does not step() it + + return streamer; + } } /** Open an input stream from a file; if it's a gzip file, returns a GZIPInputStream to unzip it. */ @@ -155,6 +155,7 @@ private static InputStream openStream(Path path) throws IOException { final SeekableByteChannel byteChannel = Files.newByteChannel(path); InputStream stream = Channels.newInputStream(byteChannel); String name = Normalizer.lowerCase(path.getFileName().toString()); + if (name.endsWith(".gz") || name.endsWith(".z")) { final boolean zipped = (stream.read() == 0x1f && stream.read() == 0x8b); // gzip magic bytes byteChannel.position(0); // reset to start of file @@ -220,7 +221,7 @@ static class CharsetDoc { } static Document parseInputStream(@Nullable InputStream input, @Nullable String charsetName, String baseUri, Parser parser) throws IOException { - if (input == null) // empty body // todo reconsider? + if (input == null) // empty body // to do reconsider? return new Document(baseUri); final Document doc; @@ -375,7 +376,7 @@ static ByteBuffer emptyByteBuffer() { return null; } - private @Nullable static String validateCharset(@Nullable String cs) { + @Nullable private static String validateCharset(@Nullable String cs) { if (cs == null || cs.length() == 0) return null; cs = cs.trim().replaceAll("[\"']", ""); try { @@ -401,7 +402,7 @@ static String mimeBoundary() { } private static @Nullable BomCharset detectCharsetFromBom(final ByteBuffer byteData) { - @SuppressWarnings("UnnecessaryLocalVariable") final Buffer buffer = byteData; // .mark and rewind used to return Buffer, now ByteBuffer, so cast for backward compat + final Buffer buffer = byteData; // .mark and rewind used to return Buffer, now ByteBuffer, so cast for backward compat buffer.mark(); byte[] bom = new byte[4]; if (byteData.remaining() >= bom.length) { @@ -430,4 +431,4 @@ public BomCharset(String charset, boolean offset) { this.offset = offset; } } -} +} \ No newline at end of file diff --git a/src/main/java/org/jsoup/helper/HttpConnection.java b/src/main/java/org/jsoup/helper/HttpConnection.java index 1ca31d321b..d21b029778 100644 --- a/src/main/java/org/jsoup/helper/HttpConnection.java +++ b/src/main/java/org/jsoup/helper/HttpConnection.java @@ -57,7 +57,6 @@ * Implementation of {@link Connection}. * @see org.jsoup.Jsoup#connect(String) */ -@SuppressWarnings("CharsetObjectCanBeUsed") public class HttpConnection implements Connection { public static final String CONTENT_ENCODING = "Content-Encoding"; /** @@ -389,7 +388,7 @@ public Connection postDataCharset(String charset) { } @SuppressWarnings("unchecked") - private static abstract class Base> implements Connection.Base { + private abstract static class Base> implements Connection.Base { private static final URL UnsetUrl; // only used if you created a new Request() static { try { @@ -796,7 +795,7 @@ public static class Response extends HttpConnection.Base im private @Nullable ControllableInputStream bodyStream; private @Nullable HttpURLConnection conn; private @Nullable String charset; - private @Nullable final String contentType; + @Nullable private final String contentType; private boolean executed = false; private boolean inputStreamRead = false; private int numRedirects = 0; @@ -970,7 +969,7 @@ private InputStream prepareParse() { @Override public Document parse() throws IOException { InputStream stream = prepareParse(); Document doc = DataUtil.parseInputStream(stream, charset, url.toExternalForm(), req.parser()); - doc.connection(new HttpConnection(req, this)); // because we're static, don't have the connection obj. // todo - maybe hold in the req? + doc.connection(new HttpConnection(req, this)); // because we're static, don't have the connection obj. // to do - maybe hold in the req? charset = doc.outputSettings().charset().name(); // update charset from meta-equiv, possibly safeClose(); return doc; @@ -980,7 +979,7 @@ private InputStream prepareParse() { InputStream stream = prepareParse(); String baseUri = url.toExternalForm(); DataUtil.CharsetDoc charsetDoc = DataUtil.detectCharset(stream, charset, baseUri, req.parser()); - // note that there may be a document in CharsetDoc as a result of scanning meta-data -- but as requires a stream parse, it is not used here. todo - revisit. + // note that there may be a document in CharsetDoc as a result of scanning meta-data -- but as requires a stream parse, it is not used here. to do - revisit. // set up the stream parser and rig this connection up to the parsed doc: StreamParser streamer = new StreamParser(req.parser()); @@ -994,7 +993,8 @@ private InputStream prepareParse() { return streamer; } - private void prepareByteData() { + @SuppressWarnings("removal") + private void prepareByteData() { Validate.isTrue(executed, "Request must be executed (with .execute(), .get(), or .post() before getting response body"); if (bodyStream != null && byteData == null) { Validate.isFalse(inputStreamRead, "Request has already been read (with .parse())"); @@ -1231,12 +1231,12 @@ private static boolean looksLikeUtf8(byte[] input) { return foundNonAscii; } - private @Nullable static String setOutputContentType(final Connection.Request req) { + @Nullable private static String setOutputContentType(final Connection.Request req) { final String contentType = req.header(CONTENT_TYPE); String bound = null; if (contentType != null) { // no-op; don't add content type as already set (e.g. for requestBody()) - // todo - if content type already set, we could add charset + // to do - if content type already set, we could add charset // if user has set content type to multipart/form-data, auto add boundary. if(contentType.contains(MULTIPART_FORM_DATA) && !contentType.contains("boundary")) { diff --git a/src/main/java/org/jsoup/helper/UrlBuilder.java b/src/main/java/org/jsoup/helper/UrlBuilder.java index 30213d3768..c275fca668 100644 --- a/src/main/java/org/jsoup/helper/UrlBuilder.java +++ b/src/main/java/org/jsoup/helper/UrlBuilder.java @@ -90,12 +90,11 @@ private static void appendToAscii(String s, boolean spaceAsPlus, StringBuilder s } else if (c > 127) { // out of ascii range sb.append(URLEncoder.encode(new String(Character.toChars(c)), UTF_8.name())); // ^^ is a bit heavy-handed - if perf critical, we could optimize - if (Character.charCount(c) == 2) i++; // advance past supplemental + if (Character.charCount(c) == 2) + i++; // advance past supplemental } else { sb.append((char) c); } } } - - -} +} \ No newline at end of file diff --git a/src/main/java/org/jsoup/helper/ValidationException.java b/src/main/java/org/jsoup/helper/ValidationException.java index 916cf12889..8a1a66284f 100644 --- a/src/main/java/org/jsoup/helper/ValidationException.java +++ b/src/main/java/org/jsoup/helper/ValidationException.java @@ -6,6 +6,7 @@ /** Validation exceptions, as thrown by the methods in {@link Validate}. */ +@SuppressWarnings("serial") public class ValidationException extends IllegalArgumentException { public static final String Validator = Validate.class.getName(); @@ -31,4 +32,4 @@ public synchronized Throwable fillInStackTrace() { return this; } -} +} \ No newline at end of file diff --git a/src/main/java/org/jsoup/helper/W3CDom.java b/src/main/java/org/jsoup/helper/W3CDom.java index 6ce0abd9e5..715ee8db90 100644 --- a/src/main/java/org/jsoup/helper/W3CDom.java +++ b/src/main/java/org/jsoup/helper/W3CDom.java @@ -136,7 +136,7 @@ public static String asString(Document doc, @Nullable Map proper transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, doctype.getPublicId()); if (!StringUtil.isBlank(doctype.getSystemId())) transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doctype.getSystemId()); - // handle for legacy dom. TODO: nicer if + // handle for legacy dom. TO DO: nicer if else if (doctype.getName().equalsIgnoreCase("html") && StringUtil.isBlank(doctype.getPublicId()) && StringUtil.isBlank(doctype.getSystemId())) @@ -158,12 +158,12 @@ static Properties propertiesFromMap(Map map) { } /** Canned default for HTML output. */ - public static HashMap OutputHtml() { + public static Map OutputHtml() { return methodMap("html"); } /** Canned default for XML output. */ - public static HashMap OutputXml() { + public static Map OutputXml() { return methodMap("xml"); } @@ -353,7 +353,7 @@ protected static class W3CBuilder implements NodeVisitor { private final Stack> namespacesStack = new Stack<>(); // stack of namespaces, prefix => urn private Node dest; private Syntax syntax = Syntax.xml; // the syntax (to coerce attributes to). From the input doc if available. - /*@Nullable*/ private final org.jsoup.nodes.Element contextElement; // todo - unsure why this can't be marked nullable? + /*@Nullable*/ private final org.jsoup.nodes.Element contextElement; // to do - unsure why this can't be marked nullable? public W3CBuilder(Document doc) { this.doc = doc; @@ -414,6 +414,7 @@ private void append(Node append, org.jsoup.nodes.Node source) { dest.appendChild(append); } + @Override public void tail(org.jsoup.nodes.Node source, int depth) { if (source instanceof org.jsoup.nodes.Element && dest.getParentNode() instanceof Element) { dest = dest.getParentNode(); // undescend @@ -454,6 +455,5 @@ private String updateNamespaces(org.jsoup.nodes.Element el) { int pos = el.tagName().indexOf(':'); return pos > 0 ? el.tagName().substring(0, pos) : ""; } - } -} +} \ No newline at end of file diff --git a/src/main/java/org/jsoup/internal/ControllableInputStream.java b/src/main/java/org/jsoup/internal/ControllableInputStream.java index 912f63e6a4..236452c539 100644 --- a/src/main/java/org/jsoup/internal/ControllableInputStream.java +++ b/src/main/java/org/jsoup/internal/ControllableInputStream.java @@ -1,6 +1,5 @@ package org.jsoup.internal; -import org.jsoup.helper.DataUtil; import org.jsoup.helper.Validate; import java.io.BufferedInputStream; @@ -110,13 +109,11 @@ public static ByteBuffer readToByteBuffer(InputStream in, int max) throws IOExce return ByteBuffer.wrap(outStream.toByteArray()); } - @SuppressWarnings("NonSynchronizedMethodOverridesSynchronizedMethod") // not synchronized in later JDKs @Override public void reset() throws IOException { super.reset(); remaining = maxSize - markPos; } - @SuppressWarnings("NonSynchronizedMethodOverridesSynchronizedMethod") // not synchronized in later JDKs @Override public void mark(int readlimit) { super.mark(readlimit); markPos = maxSize - remaining; @@ -140,4 +137,4 @@ private boolean expired() { public BufferedInputStream inputStream() { return buff; } -} +} \ No newline at end of file diff --git a/src/main/java/org/jsoup/parser/CharacterReader.java b/src/main/java/org/jsoup/parser/CharacterReader.java index 9710c414a9..8cccd3f51a 100644 --- a/src/main/java/org/jsoup/parser/CharacterReader.java +++ b/src/main/java/org/jsoup/parser/CharacterReader.java @@ -1,12 +1,12 @@ package org.jsoup.parser; -import org.jsoup.UncheckedIOException; import org.jsoup.helper.Validate; import org.jspecify.annotations.Nullable; import java.io.IOException; import java.io.Reader; import java.io.StringReader; +import java.io.UncheckedIOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; diff --git a/src/main/java/org/jsoup/select/Elements.java b/src/main/java/org/jsoup/select/Elements.java index c344f2e06d..e36ec5da9f 100644 --- a/src/main/java/org/jsoup/select/Elements.java +++ b/src/main/java/org/jsoup/select/Elements.java @@ -27,9 +27,9 @@ replace} Elements in the list will also act on the underlying {@link org.jsoup.nodes.Document DOM}.

@author Jonathan Hedley, jonathan@hedley.net */ +@SuppressWarnings("serial") public class Elements extends ArrayList { - public Elements() { - } + public Elements() {} public Elements(int initialCapacity) { super(initialCapacity); @@ -55,8 +55,9 @@ public Elements(Element... elements) { public Elements clone() { Elements clone = new Elements(size()); - for(Element e : this) + for(Element e : this) { clone.add(e.clone()); + } return clone; } diff --git a/src/main/java/org/jsoup/select/Selector.java b/src/main/java/org/jsoup/select/Selector.java index 322cfa07bc..2b2fcbe7d6 100644 --- a/src/main/java/org/jsoup/select/Selector.java +++ b/src/main/java/org/jsoup/select/Selector.java @@ -168,7 +168,8 @@ static Elements filterOut(Collection elements, Collection outs return Collector.findFirst(QueryParser.parse(cssQuery), root); } - public static class SelectorParseException extends IllegalStateException { + @SuppressWarnings("serial") + public static class SelectorParseException extends IllegalStateException { public SelectorParseException(String msg) { super(msg); } diff --git a/src/test/java/org/jsoup/parser/StreamParserTest.java b/src/test/java/org/jsoup/parser/StreamParserTest.java index f81bdb0ffc..7f8e2322d2 100644 --- a/src/test/java/org/jsoup/parser/StreamParserTest.java +++ b/src/test/java/org/jsoup/parser/StreamParserTest.java @@ -23,6 +23,7 @@ /** Tests for the StreamParser. There are also some tests in {@link org.jsoup.integration.ConnectTest}. */ +@SuppressWarnings("resource") class StreamParserTest { @Test @@ -37,7 +38,7 @@ void canStream() { } } - @Test + @Test void canStreamXml() { String html = "
D1
D2

P One

P Two

D3

P three

"; try (StreamParser parser = new StreamParser(Parser.xmlParser()).parse(html, "")) { @@ -263,7 +264,8 @@ static void trackSeen(Element el, StringBuilder actual) { @Test void closedOnComplete() throws IOException { StreamParser streamer = basic(); - Document doc = streamer.complete(); + @SuppressWarnings("unused") + Document doc = streamer.complete(); assertTrue(isClosed(streamer)); }