Skip to content

Commit 6557bfb

Browse files
committed
cleanup uses of deprecated Guava APIs
1 parent 3be8d57 commit 6557bfb

File tree

7 files changed

+24
-17
lines changed

7 files changed

+24
-17
lines changed

src/main/java/org/owasp/html/AutoCloseableHtmlStreamRenderer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
import javax.annotation.WillCloseWhenClosed;
99

10-
import com.google.common.base.Throwables;
11-
1210
final class AutoCloseableHtmlStreamRenderer extends HtmlStreamRenderer
1311
// This is available on JDK6 and makes this class extend AutoCloseable.
1412
implements Closeable {
@@ -83,8 +81,10 @@ static void closeIfAnyCloseable(Object closeable) throws IOException {
8381
Throwable tgt = ex.getTargetException();
8482
if (tgt instanceof IOException) {
8583
throw (IOException) tgt;
84+
} else if (tgt instanceof RuntimeException) {
85+
throw (RuntimeException) tgt;
8686
} else {
87-
Throwables.propagate(tgt);
87+
throw new AssertionError(null, tgt);
8888
}
8989
}
9090
}

src/main/java/org/owasp/html/Handler.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828

2929
package org.owasp.html;
3030

31-
import com.google.common.base.Throwables;
32-
3331
/**
3432
* Receives notification of problems.
3533
*
@@ -57,7 +55,11 @@ public void handle(Object x) {
5755
*/
5856
public static final Handler<Throwable> PROPAGATE = new Handler<Throwable>() {
5957
public void handle(Throwable th) {
60-
Throwables.propagate(th);
58+
if (th instanceof RuntimeException) {
59+
throw (RuntimeException) th;
60+
} else {
61+
throw new AssertionError(null, th);
62+
}
6163
}
6264
};
6365
}

src/main/java/org/owasp/html/examples/EbayPolicyExample.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040

4141
import com.google.common.base.Charsets;
4242
import com.google.common.base.Predicate;
43-
import com.google.common.base.Throwables;
4443
import com.google.common.io.CharStreams;
4544

4645
/**
@@ -217,7 +216,8 @@ public static void main(String[] args) throws IOException {
217216
// Receives notifications on a failure to write to the output.
218217
new Handler<IOException>() {
219218
public void handle(IOException ex) {
220-
Throwables.propagate(ex); // System.out suppresses IOExceptions
219+
// System.out suppresses IOExceptions
220+
throw new AssertionError(null, ex);
221221
}
222222
},
223223
// Our HTML parser is very lenient, but this receives notifications on
@@ -242,7 +242,7 @@ public boolean apply(String s) {
242242
// java.util.function.Predicate.
243243
// For some reason the default test method implementation that calls
244244
// through to apply is not assumed here.
245-
@SuppressWarnings("unused")
245+
@SuppressWarnings("all")
246246
public boolean test(String s) {
247247
return apply(s);
248248
}

src/main/java/org/owasp/html/examples/SlashdotPolicyExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040

4141
import com.google.common.base.Charsets;
4242
import com.google.common.base.Function;
43-
import com.google.common.base.Throwables;
4443
import com.google.common.io.CharStreams;
4544

4645
/**
@@ -108,7 +107,8 @@ public static void main(String[] args) throws IOException {
108107
// Receives notifications on a failure to write to the output.
109108
new Handler<IOException>() {
110109
public void handle(IOException ex) {
111-
Throwables.propagate(ex); // System.out suppresses IOExceptions
110+
// System.out suppresses IOExceptions
111+
throw new AssertionError(null, ex);
112112
}
113113
},
114114
// Our HTML parser is very lenient, but this receives notifications on

src/test/java/org/owasp/html/Benchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class Benchmark {
5959
* specifies a benchmark to run and unspecified ones are not run.
6060
*/
6161
public static void main(String[] args) throws Exception {
62-
String html = Files.toString(new File(args[0]), Charsets.UTF_8);
62+
String html = Files.asCharSource(new File(args[0]), Charsets.UTF_8).read();
6363

6464
boolean timeLibhtmlparser = true;
6565
boolean timeSanitize = true;

src/test/java/org/owasp/html/ExamplesTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
import java.io.PrintStream;
3535
import java.lang.reflect.Method;
3636

37-
import com.google.common.base.Throwables;
38-
3937
import org.junit.Test;
4038
import org.owasp.html.examples.EbayPolicyExample;
4139

@@ -66,7 +64,11 @@ public static final void testExamplesRun() throws Exception {
6664
System.err.println(
6765
"Example " + exampleClass.getSimpleName() + "\n"
6866
+ captured.toString("UTF-8"));
69-
Throwables.propagate(ex);
67+
if (ex instanceof RuntimeException) {
68+
throw (RuntimeException) ex;
69+
} else {
70+
throw new AssertionError(null, ex);
71+
}
7072
} finally {
7173
System.setIn(stdin);
7274
System.setOut(stdout);

src/test/java/org/owasp/html/HtmlSanitizerFuzzerTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.util.concurrent.TimeUnit;
3535

3636
import com.google.common.base.Charsets;
37-
import com.google.common.base.Throwables;
3837
import com.google.common.io.Resources;
3938

4039
/**
@@ -144,7 +143,11 @@ public void run() {
144143
assertTrue("seed=" + seed, executor.isTerminated());
145144
Throwable failure = failures.poll();
146145
if (failure != null) {
147-
Throwables.propagate(failure);
146+
if (failure instanceof RuntimeException) {
147+
throw (RuntimeException) failure;
148+
} else {
149+
throw new AssertionError(null, failure);
150+
}
148151
}
149152
}
150153

0 commit comments

Comments
 (0)