avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bus...@apache.org
Subject avro git commit: AVRO-1901: Record named Exception generated bad code
Date Sat, 28 Jan 2017 10:10:56 GMT
Repository: avro
Updated Branches:
  refs/heads/branch-1.7 49f3bf03d -> 3345e1323


AVRO-1901: Record named Exception generated bad code

Amending-Author: Ben McCann <bmccann@linkedin.com>

backport to branch-1.7.

Exception record for share/test/schemas/specialtypes.avdl skipped since branch-1.7 doesn't
have AVRO-1614.

Closes #188.

Signed-off-by: Sean Busbey <busbey@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/avro/repo
Commit: http://git-wip-us.apache.org/repos/asf/avro/commit/3345e132
Tree: http://git-wip-us.apache.org/repos/asf/avro/tree/3345e132
Diff: http://git-wip-us.apache.org/repos/asf/avro/diff/3345e132

Branch: refs/heads/branch-1.7
Commit: 3345e13238d1d0278a4e1da5a9df60356892193c
Parents: 49f3bf0
Author: radai-rosenblatt <radai.rosenblatt@gmail.com>
Authored: Fri Jan 13 15:22:57 2017 -0800
Committer: Sean Busbey <busbey@apache.org>
Committed: Sat Jan 28 03:54:05 2017 -0600

----------------------------------------------------------------------
 .../specific/templates/java/classic/record.vm   |  2 +-
 .../avro/compiler/TestSpecificCompiler.java     | 20 +++++++++++++++++---
 .../avro/examples/baseball/Player.java          |  2 +-
 .../tools/src/test/compiler/output/Player.java  |  2 +-
 4 files changed, 20 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/avro/blob/3345e132/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
----------------------------------------------------------------------
diff --git a/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
b/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
index 7298509..1becde0 100644
--- a/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
+++ b/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
@@ -279,7 +279,7 @@ public class ${this.mangle($schema.getName())}#if ($schema.isError())
extends or
         record.${this.mangle($field.name(), $schema.isError())} = fieldSetFlags()[$field.pos()]
? this.${this.mangle($field.name(), $schema.isError())} : (${this.javaType($field.schema())})
defaultValue(fields()[$field.pos()]);
 #end
         return record;
-      } catch (Exception e) {
+      } catch (java.lang.Exception e) {
         throw new org.apache.avro.AvroRuntimeException(e);
       }
     }

http://git-wip-us.apache.org/repos/asf/avro/blob/3345e132/lang/java/compiler/src/test/java/org/apache/avro/compiler/TestSpecificCompiler.java
----------------------------------------------------------------------
diff --git a/lang/java/compiler/src/test/java/org/apache/avro/compiler/TestSpecificCompiler.java
b/lang/java/compiler/src/test/java/org/apache/avro/compiler/TestSpecificCompiler.java
index 7c4fcc2..35c1936 100644
--- a/lang/java/compiler/src/test/java/org/apache/avro/compiler/TestSpecificCompiler.java
+++ b/lang/java/compiler/src/test/java/org/apache/avro/compiler/TestSpecificCompiler.java
@@ -56,6 +56,9 @@ public class TestSpecificCompiler {
     this.src = new File(this.schemaSrcPath);
     this.outputDir = AvroTestUtil.tempDirectory(getClass(), "specific-output");
     this.outputFile = new File(this.outputDir, "SimpleRecord.java");
+    if (outputFile.exists() && !outputFile.delete()) {
+      throw new IllegalStateException("unable to delete " + outputFile);
+    }
   }
 
   @After
@@ -100,6 +103,7 @@ public class TestSpecificCompiler {
       assertFalse("Line started with a deprecated field declaration: " + line,
         line.startsWith("@Deprecated public int value"));
     }
+    reader.close();
   }
 
   @Test
@@ -118,6 +122,7 @@ public class TestSpecificCompiler {
       assertFalse("Line started with a public field declaration: " + line,
         line.startsWith("public int value"));
     }
+    reader.close();
   }
 
   @Test
@@ -140,6 +145,7 @@ public class TestSpecificCompiler {
       assertFalse("Line started with a deprecated field declaration: " + line,
         line.startsWith("@Deprecated public int value"));
     }
+    reader.close();
   }
 
   @Test
@@ -158,6 +164,7 @@ public class TestSpecificCompiler {
         foundSetters++;
       }
     }
+    reader.close();
     assertEquals("Found the wrong number of setters", 1, foundSetters);
   }
 
@@ -176,6 +183,7 @@ public class TestSpecificCompiler {
       assertFalse("No line should include the setter: " + line,
         line.startsWith("public void setValue("));
     }
+    reader.close();
   }
 
   @Test
@@ -184,14 +192,20 @@ public class TestSpecificCompiler {
     // Generated file in default encoding
     compiler.compileToDestination(this.src, this.outputDir);
     byte[] fileInDefaultEncoding = new byte[(int) this.outputFile.length()];
-    new FileInputStream(this.outputFile).read(fileInDefaultEncoding);
-    this.outputFile.delete();
+    FileInputStream is = new FileInputStream(this.outputFile);
+    is.read(fileInDefaultEncoding);
+    is.close(); //close input stream otherwise delete might fail
+    if (!this.outputFile.delete()) {
+      throw new IllegalStateException("unable to delete " + this.outputFile); //delete otherwise
compiler might not overwrite because src timestamp hasnt changed.
+    }
     // Generate file in another encoding (make sure it has different number of bytes per
character)
     String differentEncoding = Charset.defaultCharset().equals(Charset.forName("UTF-16"))
? "UTF-32" : "UTF-16";
     compiler.setOutputCharacterEncoding(differentEncoding);
     compiler.compileToDestination(this.src, this.outputDir);
     byte[] fileInDifferentEncoding = new byte[(int) this.outputFile.length()];
-    new FileInputStream(this.outputFile).read(fileInDifferentEncoding);
+    is = new FileInputStream(this.outputFile);
+    is.read(fileInDifferentEncoding);
+    is.close();
     // Compare as bytes
     assertThat("Generated file should contain different bytes after setting non-default encoding",
       fileInDefaultEncoding, not(equalTo(fileInDifferentEncoding)));

http://git-wip-us.apache.org/repos/asf/avro/blob/3345e132/lang/java/tools/src/test/compiler/output-string/avro/examples/baseball/Player.java
----------------------------------------------------------------------
diff --git a/lang/java/tools/src/test/compiler/output-string/avro/examples/baseball/Player.java
b/lang/java/tools/src/test/compiler/output-string/avro/examples/baseball/Player.java
index 6313529..7ee67c1 100644
--- a/lang/java/tools/src/test/compiler/output-string/avro/examples/baseball/Player.java
+++ b/lang/java/tools/src/test/compiler/output-string/avro/examples/baseball/Player.java
@@ -364,7 +364,7 @@ public class Player extends org.apache.avro.specific.SpecificRecordBase
implemen
         record.last_name = fieldSetFlags()[2] ? this.last_name : (java.lang.String) defaultValue(fields()[2]);
         record.position = fieldSetFlags()[3] ? this.position : (java.util.List<avro.examples.baseball.Position>)
defaultValue(fields()[3]);
         return record;
-      } catch (Exception e) {
+      } catch (java.lang.Exception e) {
         throw new org.apache.avro.AvroRuntimeException(e);
       }
     }

http://git-wip-us.apache.org/repos/asf/avro/blob/3345e132/lang/java/tools/src/test/compiler/output/Player.java
----------------------------------------------------------------------
diff --git a/lang/java/tools/src/test/compiler/output/Player.java b/lang/java/tools/src/test/compiler/output/Player.java
index 9773c29..1b5299b 100644
--- a/lang/java/tools/src/test/compiler/output/Player.java
+++ b/lang/java/tools/src/test/compiler/output/Player.java
@@ -364,7 +364,7 @@ public class Player extends org.apache.avro.specific.SpecificRecordBase
implemen
         record.last_name = fieldSetFlags()[2] ? this.last_name : (java.lang.CharSequence)
defaultValue(fields()[2]);
         record.position = fieldSetFlags()[3] ? this.position : (java.util.List<avro.examples.baseball.Position>)
defaultValue(fields()[3]);
         return record;
-      } catch (Exception e) {
+      } catch (java.lang.Exception e) {
         throw new org.apache.avro.AvroRuntimeException(e);
       }
     }


Mime
View raw message