Skip to content

Commit f17d298

Browse files
eamonnmcmanusronshapiro
authored andcommitted
Expand the exceptions covered by the workaround for a JDK8 jar bug.
Fixes #715. RELNOTES=Expand the exceptions covered by the workaround for a JDK8 jar bug. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=240859625
1 parent a81a9e2 commit f17d298

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

value/src/main/java/com/google/auto/value/processor/TemplateVars.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ static Template parsedTemplateForResource(String resourceName) {
119119
return Template.parseFrom(resourceName, TemplateVars::readerFromResource);
120120
} catch (UnsupportedEncodingException e) {
121121
throw new AssertionError(e);
122-
} catch (IOException | NullPointerException e) {
123-
// https://github.com/google/auto/pull/439 says that we can also get NullPointerException.
122+
} catch (IOException | NullPointerException | IllegalStateException e) {
123+
// https://github.com/google/auto/pull/439 says that we can get NullPointerException.
124+
// https://github.com/google/auto/issues/715 says that we can get IllegalStateException
124125
return retryParseAfterException(resourceName, e);
125126
}
126127
}

value/src/test/java/com/google/auto/value/processor/TemplateVarsTest.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,20 @@ public void testBrokenInputStream_NullPointerException() throws Exception {
183183
doTestBrokenInputStream(new NullPointerException("BrokenInputStream"));
184184
}
185185

186+
@Test
187+
public void testBrokenInputStream_IllegalStateException() throws Exception {
188+
doTestBrokenInputStream(new IllegalStateException("BrokenInputStream"));
189+
}
190+
186191
// This is a complicated test that tries to simulates the failures that are worked around in
187192
// Template.parsedTemplateForResource. Those failures means that the InputStream returned by
188-
// ClassLoader.getResourceAsStream sometimes throws IOException or NullPointerException while it
189-
// is being read. To simulate that, we make a second ClassLoader with the same configuration as
190-
// the one that runs this test, and we override getResourceAsStream so that it wraps the returned
191-
// InputStream in a BrokenInputStream, which throws an exception after a certain number of
192-
// characters. We check that that exception was indeed seen, and that we did indeed try to read
193-
// the resource we're interested in, and that we succeeded in loading a Template nevertheless.
193+
// ClassLoader.getResourceAsStream sometimes throws IOException or NullPointerException or
194+
// IllegalStateException while it is being read. To simulate that, we make a second ClassLoader
195+
// with the same configuration as the one that runs this test, and we override getResourceAsStream
196+
// so that it wraps the returned InputStream in a BrokenInputStream, which throws an exception
197+
// after a certain number of characters. We check that that exception was indeed seen, and that
198+
// we did indeed try to read the resource we're interested in, and that we succeeded in loading a
199+
// Template nevertheless.
194200
private void doTestBrokenInputStream(Exception exception) throws Exception {
195201
URLClassLoader shadowLoader = new ShadowLoader(getClass().getClassLoader(), exception);
196202
Runnable brokenInputStreamTest =

0 commit comments

Comments
 (0)