diff options
author | Paul Duffin <paulduffin@google.com> | 2018-07-11 13:46:57 +0100 |
---|---|---|
committer | Paul Duffin <paulduffin@google.com> | 2018-07-12 13:01:57 +0100 |
commit | 8ce3b14a85056cdaf8da5980c2a569bd3d28a704 (patch) | |
tree | e0b45d2980c691c6561fc06e27012011cb85f49d | |
parent | f2096fd9a7085946be28faae6d36f24b712eb998 (diff) |
Inflater: Revert ensureOpen() changes to upstream 8u121-b13
The luni implementation of Inflater threw an IllegalStateException if
it was used after its end() method had been called but upstream throws
NullPointerException in that situation. The ojluni version was patched
in change b3c5785d in order to fix some failing tests. This change
reverts that patch and fixes the affected tests.
Throwing an NPE instead of an ISE could cause app compatibility issues
but it seems unlikely and in that case the application could simply
catch both.
An ISE is a more meaningful exception to throw but the benefit is minor
especially given that the message clearly indicates why it was thrown
and does not seem sufficient to justify carrying an additional patch.
Bug: 111061052
Test: flash, CtsLibcoreTestCases
Change-Id: I91ca999a7d3e81c571f960e01b5a2557a1676592
3 files changed, 30 insertions, 32 deletions
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/InflaterInputStreamTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/InflaterInputStreamTest.java index 6109762c83..58cdf52728 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/InflaterInputStreamTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/InflaterInputStreamTest.java @@ -488,8 +488,8 @@ public class InflaterInputStreamTest extends TestCaseWithRules { } // http://b/26462400 - public void testInflaterInputStreamWithExternalInflater() throws Exception { - InputStream base = new ByteArrayInputStream(new byte[] { 'h', 'i'}); + public void testInflaterInputStreamWithExternalInflater_3ArgConstructor() throws Exception { + InputStream base = new ByteArrayInputStream(new byte[]{'h', 'i'}); Inflater inf = new Inflater(); InflaterInputStream iis = new InflaterInputStream(base, inf, 512); @@ -497,17 +497,21 @@ public class InflaterInputStreamTest extends TestCaseWithRules { try { inf.reset(); fail(); - } catch (IllegalStateException espected) { + } catch (NullPointerException expected) { // Expected because the inflater should've been closed when the stream was. } + } - inf = new Inflater(); - iis = new InflaterInputStream(base, inf); + // http://b/26462400 + public void testInflaterInputStreamWithExternalInflater_2ArgConstructor() throws Exception { + InputStream base = new ByteArrayInputStream(new byte[]{'h', 'i'}); + Inflater inf = new Inflater(); + InflaterInputStream iis = new InflaterInputStream(base, inf); iis.close(); try { inf.reset(); fail(); - } catch (IllegalStateException espected) { + } catch (NullPointerException expected) { // Expected because the inflater should've been closed when the stream was. } } diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/InflaterTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/InflaterTest.java index a15a5cf30c..52762463d2 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/InflaterTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/zip/InflaterTest.java @@ -53,11 +53,10 @@ public class InflaterTest extends TestCaseWithRules { inflate.setInput(byteArray); inflate.end(); - // Note that the RI throws an NPE here instead of an ISE (???). try { inflate.reset(); - inflate.setInput(byteArray); - } catch (IllegalStateException expected) { + } catch (NullPointerException expected) { + // Expected } Inflater i = new Inflater(); @@ -424,11 +423,11 @@ public class InflaterTest extends TestCaseWithRules { inflate.end(); try { inflate.inflate(outPutInf, offSet, 1); - fail("IllegalStateException expected"); + fail("NullPointerException expected"); } catch (DataFormatException e) { fail("Invalid input to be decompressed"); - } catch (IllegalStateException e) { - //expected + } catch (NullPointerException expected) { + // Expected } } @@ -1002,9 +1001,9 @@ public class InflaterTest extends TestCaseWithRules { infl1.end(); try { infl1.setDictionary(dictionary2.getBytes()); - fail("IllegalStateException expected"); - } catch (IllegalStateException ise) { - //expected + fail("NullPointerException expected"); + } catch (NullPointerException expected) { + // Expected } } @@ -1137,41 +1136,38 @@ public class InflaterTest extends TestCaseWithRules { try { inflate.getAdler(); - fail("IllegalStateException expected"); - } catch (IllegalStateException expected) { - //expected + fail("NullPointerException expected"); + } catch (NullPointerException expected) { + // Expected } try { inflate.getBytesRead(); fail("NullPointerException expected"); - } catch (IllegalStateException expected) { } catch (NullPointerException expected) { - //expected + // Expected } try { inflate.getBytesWritten(); fail("NullPointerException expected"); } catch (NullPointerException expected) { - } catch (IllegalStateException expected) { - //expected + // Expected } try { inflate.getTotalIn(); - fail("IllegalStateException expected"); - } catch (IllegalStateException ise) { - //expected + fail("NullPointerException expected"); + } catch (NullPointerException expected) { + // Expected } try { inflate.getTotalOut(); - fail("IllegalStateException expected"); - } catch (IllegalStateException ise) { - //expected + fail("NullPointerException expected"); + } catch (NullPointerException expected) { + // Expected } - } } diff --git a/ojluni/src/main/java/java/util/zip/Inflater.java b/ojluni/src/main/java/java/util/zip/Inflater.java index bd400a39f4..eb8754ee27 100644 --- a/ojluni/src/main/java/java/util/zip/Inflater.java +++ b/ojluni/src/main/java/java/util/zip/Inflater.java @@ -412,10 +412,8 @@ class Inflater { private void ensureOpen () { assert Thread.holdsLock(zsRef); - // Android-changed: Throw IllegalStateException instead of a NullPointerException. - // Required for various Inflater related tests to pass. if (zsRef.address() == 0) - throw new IllegalStateException("Inflater has been closed"); + throw new NullPointerException("Inflater has been closed"); } boolean ended() { |