Repository: googleapis/java-storage (java)

Issue:
BlobReadChannel read trows a non-IOException
Couldn't find this discussed anywhere and thought it belonged here, I hope you agree, please let me know otherwise.

[`BlobReadChannel.read`](https://github.com/googleapis/java-storage/blob/035ae2ad876fc9d17f86449d17f675000831b185/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobReadChannel.java#L114) is annotated with `@throws IOException` which fits the interface and expected behaviour with nio (e.g. I get the expected `IOException` on read in the standard `ReadableBytesChannel` interface and in an input stream created with `Channels.newInputStream`)

However, at least one of the [current exceptions](https://github.com/googleapis/java-storage/blob/035ae2ad876fc9d17f86449d17f675000831b185/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobReadChannel.java#L136) thrown is `StorageException`, which is *not* an `IOException`, forcing users to know that this particular `ReadbleBytesChannel` throws another exception.

Could the exceptions thrown here be modified to inherit from `IOException` instead?

Pull request:
fix: throw io exception instead of storage exception
Fixes #219 


Patch:
diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobReadChannel.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobReadChannel.java
index cd9f08d9..c5fce5bd 100644
--- a/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobReadChannel.java
+++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobReadChannel.java
@@ -133,12 +133,12 @@ class BlobReadChannel implements ReadChannel {
         if (result.y().length > 0 && lastEtag != null && !Objects.equals(result.x(), lastEtag)) {
           StringBuilder messageBuilder = new StringBuilder();
           messageBuilder.append("Blob ").append(blob).append(" was updated while reading");
-          throw new StorageException(0, messageBuilder.toString());
+          throw new IOException(messageBuilder.toString());
         }
         lastEtag = result.x();
         buffer = result.y();
       } catch (RetryHelper.RetryHelperException e) {
-        throw StorageException.translateAndThrow(e);
+        throw new IOException(e);
       }
       if (toRead > buffer.length) {
         endOfStream = true;
diff --git a/pom.xml b/pom.xml
index 6591aa40..ccd699de 100644
--- a/pom.xml
+++ b/pom.xml
@@ -63,10 +63,10 @@
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
     <github.global.server>github</github.global.server>
     <site.installationModule>google-cloud-storage-parent</site.installationModule>
-    <google.core.version>1.93.3</google.core.version>
+    <google.core.version>1.93.4</google.core.version>
     <google.api-common.version>1.9.0</google.api-common.version>
     <junit.version>4.13</junit.version>
-    <threeten.version>1.4.2</threeten.version>
+    <threeten.version>1.4.3</threeten.version>
     <javax.annotations.version>1.3.2</javax.annotations.version>
     <animal-sniffer.version>1.18</animal-sniffer.version>
     <opencensus.version>0.24.0</opencensus.version>
@@ -103,14 +103,14 @@
       <dependency>
         <groupId>io.grpc</groupId>
         <artifactId>grpc-bom</artifactId>
-        <version>1.27.2</version>
+        <version>1.28.1</version>
         <type>pom</type>
         <scope>import</scope>
       </dependency>
       <dependency>
         <groupId>com.google.api</groupId>
         <artifactId>gax-bom</artifactId>
-        <version>1.54.0</version>
+        <version>1.56.0</version>
         <type>pom</type>
         <scope>import</scope>
       </dependency>
diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml
index 385e9df3..597e0599 100644
--- a/samples/install-without-bom/pom.xml
+++ b/samples/install-without-bom/pom.xml
@@ -14,7 +14,7 @@
   <parent>
     <groupId>com.google.cloud.samples</groupId>
     <artifactId>shared-configuration</artifactId>
-    <version>1.0.14</version>
+    <version>1.0.15</version>
   </parent>
 
   <properties>
diff --git a/samples/pom.xml b/samples/pom.xml
index 0361d78e..351cabdd 100644
--- a/samples/pom.xml
+++ b/samples/pom.xml
@@ -18,7 +18,7 @@
   <parent>
     <groupId>com.google.cloud.samples</groupId>
     <artifactId>shared-configuration</artifactId>
-    <version>1.0.14</version>
+    <version>1.0.15</version>
   </parent>
 
   <properties>
diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml
index 0bcbae55..b45a8cc1 100644
--- a/samples/snapshot/pom.xml
+++ b/samples/snapshot/pom.xml
@@ -14,7 +14,7 @@
   <parent>
     <groupId>com.google.cloud.samples</groupId>
     <artifactId>shared-configuration</artifactId>
-    <version>1.0.14</version>
+    <version>1.0.15</version>
   </parent>
 
   <properties>
diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml
index 0f274f99..2d979c7e 100644
--- a/samples/snippets/pom.xml
+++ b/samples/snippets/pom.xml
@@ -14,7 +14,7 @@
   <parent>
     <groupId>com.google.cloud.samples</groupId>
     <artifactId>shared-configuration</artifactId>
-    <version>1.0.14</version>
+    <version>1.0.15</version>
   </parent>
 
   <properties>
@@ -30,7 +30,7 @@
       <dependency>
         <groupId>com.google.cloud</groupId>
         <artifactId>libraries-bom</artifactId>
-        <version>4.4.0</version>
+        <version>4.4.1</version>
         <type>pom</type>
         <scope>import</scope>
       </dependency>


Test patch:
diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/BlobReadChannelTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/BlobReadChannelTest.java
index f1388ebe..dafb0b2a 100644
--- a/google-cloud-storage/src/test/java/com/google/cloud/storage/BlobReadChannelTest.java
+++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/BlobReadChannelTest.java
@@ -23,6 +23,7 @@ import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.verify;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -71,7 +72,7 @@ public class BlobReadChannelTest {
   }
 
   @After
-  public void tearDown() throws Exception {
+  public void tearDown() {
     verify(rpcFactoryMock, storageRpcMock);
   }
 
@@ -154,7 +155,7 @@ public class BlobReadChannelTest {
     reader = new BlobReadChannel(options, BLOB_ID, EMPTY_RPC_OPTIONS);
     assertTrue(reader.isOpen());
     reader.close();
-    assertTrue(!reader.isOpen());
+    assertFalse(reader.isOpen());
   }
 
   @Test
@@ -190,7 +191,7 @@ public class BlobReadChannelTest {
     try {
       reader.read(secondReadBuffer);
       fail("Expected ReadChannel read to throw StorageException");
-    } catch (StorageException ex) {
+    } catch (IOException ex) {
       StringBuilder messageBuilder = new StringBuilder();
       messageBuilder.append("Blob ").append(blobId).append(" was updated while reading");
       assertEquals(messageBuilder.toString(), ex.getMessage());
diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java
index 6abc233f..52a6acd7 100644
--- a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java
+++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java
@@ -1751,14 +1751,14 @@ public class ITStorageTest {
         storage.reader(blob.getBlobId(), Storage.BlobSourceOption.metagenerationMatch(-1L))) {
       reader.read(ByteBuffer.allocate(42));
       fail("StorageException was expected");
-    } catch (StorageException ex) {
+    } catch (IOException ex) {
       // expected
     }
     try (ReadChannel reader =
         storage.reader(blob.getBlobId(), Storage.BlobSourceOption.generationMatch(-1L))) {
       reader.read(ByteBuffer.allocate(42));
       fail("StorageException was expected");
-    } catch (StorageException ex) {
+    } catch (IOException ex) {
       // expected
     }
     BlobId blobIdWrongGeneration = BlobId.of(BUCKET, blobName, -1L);
@@ -1766,7 +1766,7 @@ public class ITStorageTest {
         storage.reader(blobIdWrongGeneration, Storage.BlobSourceOption.generationMatch())) {
       reader.read(ByteBuffer.allocate(42));
       fail("StorageException was expected");
-    } catch (StorageException ex) {
+    } catch (IOException ex) {
       // expected
     }
   }
@@ -1798,7 +1798,7 @@ public class ITStorageTest {
       readBytes = ByteBuffer.allocate(chunkSize);
       reader.read(readBytes);
       fail("StorageException was expected");
-    } catch (StorageException ex) {
+    } catch (IOException ex) {
       StringBuilder messageBuilder = new StringBuilder();
       messageBuilder.append("Blob ").append(blob.getBlobId()).append(" was updated while reading");
       assertEquals(messageBuilder.toString(), ex.getMessage());