[ 
https://issues.apache.org/jira/browse/AVRO-2127?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16680064#comment-16680064
 ] 

ASF GitHub Bot commented on AVRO-2127:
--------------------------------------

dkulp closed pull request #273: AVRO-2127 Make InvalidAvroMagicException thrown 
if stream header is corrupted
URL: https://github.com/apache/avro/pull/273
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/lang/java/avro/src/main/java/org/apache/avro/file/DataFileReader.java 
b/lang/java/avro/src/main/java/org/apache/avro/file/DataFileReader.java
index 0d5e5c1b7..8c0279fd8 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/file/DataFileReader.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/file/DataFileReader.java
@@ -47,7 +47,7 @@
                                              DatumReader<D> reader)
     throws IOException {
     if (in.length() < MAGIC.length)
-      throw new IOException("Not an Avro data file");
+      throw new EOFException("Not an Avro data file");
 
     // read magic header
     byte[] magic = new byte[MAGIC.length];
@@ -60,7 +60,7 @@
     if (Arrays.equals(DataFileReader12.MAGIC, magic)) // 1.2 format
       return new DataFileReader12<D>(in, reader);
 
-    throw new IOException("Not an Avro data file");
+    throw new InvalidAvroMagicException("Not an Avro data file");
   }
 
   /**
diff --git 
a/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java 
b/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java
index 0a2747666..f1803f8a0 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java
@@ -102,7 +102,7 @@ void initialize(InputStream in) throws IOException {
       throw new IOException("Not an Avro data file.", e);
     }
     if (!Arrays.equals(DataFileConstants.MAGIC, magic))
-      throw new IOException("Not an Avro data file.");
+      throw new InvalidAvroMagicException("Not an Avro data file.");
 
     long l = vin.readMapStart();                  // read meta data
     if (l > 0) {
diff --git 
a/lang/java/avro/src/main/java/org/apache/avro/file/InvalidAvroMagicException.java
 
b/lang/java/avro/src/main/java/org/apache/avro/file/InvalidAvroMagicException.java
new file mode 100644
index 000000000..ae27dc381
--- /dev/null
+++ 
b/lang/java/avro/src/main/java/org/apache/avro/file/InvalidAvroMagicException.java
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.avro.file;
+
+import java.io.IOException;
+
+public class InvalidAvroMagicException extends IOException {
+    public InvalidAvroMagicException(String message){ super(message); }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Throwing more specific exception if an avro file has currupted magic
> --------------------------------------------------------------------
>
>                 Key: AVRO-2127
>                 URL: https://issues.apache.org/jira/browse/AVRO-2127
>             Project: Apache Avro
>          Issue Type: Improvement
>          Components: java
>    Affects Versions: 1.8.2
>            Reporter: Dmitrii Bundin
>            Assignee: Dmitrii Bundin
>            Priority: Minor
>
> Curently we have IOException thrown if an avro file has incorrect magic. 
> It seems reasonable to throw a subclass of IOException to be able to handle 
> incorrect magic (in case length are match) in user code.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to