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

Switch to Java's UncheckedIOException. #1989

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jsoup is an open source project distributed under the liberal [MIT license](http
3. Enjoy!

### Android support
When used in Android projects, [core library desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) should be enabled to support Java 8+ features.
When used in Android projects, [core library desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) with the [NIO specification](https://developer.android.com/studio/write/java11-nio-support-table) should be enabled to support Java 8+ features.

## Development and support
If you have any questions on how to use jsoup, or have ideas for future development, please get in touch via the [mailing list](https://jsoup.org/discussion).
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<ignore>java.util.function.Consumer</ignore>
<ignore>java.util.function.Supplier</ignore>
<ignore>java.lang.ThreadLocal</ignore>
<ignore>java.io.UncheckedIOException</ignore>
</ignores>
<!-- ^ Provided by https://developer.android.com/studio/write/java8-support#library-desugaring
Possibly OK to remove androidscents; keep for now to validate other additions are supported. -->
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jsoup/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.CookieStore;
import java.net.Proxy;
import java.net.URL;
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/jsoup/UncheckedIOException.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

import java.io.IOException;

public class UncheckedIOException extends RuntimeException {
/**
* @deprecated Use {@link java.io.UncheckedIOException} instead. This class acted as a compatibility shim for Java
* versions prior to 1.8.
*/
// todo annotate @Deprecated in next release (after previous @Deprecations clear)
public class UncheckedIOException extends java.io.UncheckedIOException {
Dismissed Show dismissed Hide dismissed
public UncheckedIOException(IOException cause) {
super(cause);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jsoup/helper/DataUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jsoup.helper;

import org.jsoup.UncheckedIOException;
import org.jsoup.internal.ConstrainableInputStream;
import org.jsoup.internal.Normalizer;
import org.jsoup.internal.StringUtil;
Expand All @@ -23,6 +22,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
Expand Down Expand Up @@ -163,7 +163,7 @@ static Document parseInputStream(@Nullable @WillClose InputStream input, @Nullab
else
doc = parser.parseInput(defaultDecoded.toString(), baseUri);
} catch (UncheckedIOException e) {
throw e.ioException();
throw e.getCause();
}

// look for <meta http-equiv="Content-Type" content="text/html;charset=gb2312"> or HTML5 <meta charset="gb2312">
Expand Down Expand Up @@ -218,7 +218,7 @@ else if (first instanceof Comment) {
doc = parser.parseInput(reader, baseUri);
} catch (UncheckedIOException e) {
// io exception when parsing (not seen before because reading the stream as we go)
throw e.ioException();
throw e.getCause();
}
Charset charset = charsetName.equals(defaultCharsetName) ? UTF_8 : Charset.forName(charsetName);
doc.outputSettings().charset(charset);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/jsoup/integration/SessionIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.UncheckedIOException;
import org.jsoup.integration.servlets.FileServlet;
import org.jsoup.integration.servlets.SlowRider;
import org.jsoup.nodes.Document;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.concurrent.atomic.AtomicInteger;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/jsoup/parser/CharacterReaderTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.jsoup.parser;

import org.jsoup.UncheckedIOException;
import org.jsoup.integration.ParseTest;
import org.junit.jupiter.api.Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.io.UncheckedIOException;

import static org.junit.jupiter.api.Assertions.*;

Expand Down