Repository: avro
Updated Branches:
  refs/heads/master 27cb9e271 -> be33922c0


AVRO-1901: Record named Exception generated bad code


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

Branch: refs/heads/master
Commit: be33922c03bd229b885fb9d664b55ce308f6ffaf
Parents: 27cb9e2
Author: radai-rosenblatt <radai.rosenbl...@gmail.com>
Authored: Tue Sep 6 09:16:42 2016 -0700
Committer: Niels Basjes <nbas...@bol.com>
Committed: Mon Sep 19 10:15:46 2016 +0200

----------------------------------------------------------------------
 CHANGES.txt                                     |  3 +++
 .../compiler/specific/SpecificCompiler.java     |  1 +
 .../specific/templates/java/classic/record.vm   |  2 +-
 .../compiler/specific/TestSpecificCompiler.java | 21 +++++++++++++++++---
 .../avro/examples/baseball/Player.java          |  2 +-
 .../tools/src/test/compiler/output/Player.java  |  2 +-
 share/test/schemas/specialtypes.avdl            |  3 +++
 7 files changed, 28 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/avro/blob/be33922c/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index aa72209..28fdf93 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -60,6 +60,9 @@ Trunk (not yet released)
 
     AVRO-1914: Fix licencing errors reported by rat. (Niels Basjes)
 
+    AVRO-1901: Record named "Exception" generated bad code.
+    (Radai Rosenblatt via Niels Basjes)
+
 Avro 1.8.1 (14 May 2016)
 
   INCOMPATIBLE CHANGES

http://git-wip-us.apache.org/repos/asf/avro/blob/be33922c/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
----------------------------------------------------------------------
diff --git 
a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
 
b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
index 5b6b3bb..2959493 100644
--- 
a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
+++ 
b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
@@ -406,6 +406,7 @@ public class SpecificCompiler {
     return outputFile;
   }
 
+  //package private for testing purposes
   String makePath(String name, String space) {
     if (space == null || space.isEmpty()) {
       return name + suffix;

http://git-wip-us.apache.org/repos/asf/avro/blob/be33922c/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 15ea734..d5ace4d 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
@@ -425,7 +425,7 @@ public class ${this.mangle($schema.getName())}#if 
($schema.isError()) extends or
 #end
 #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/be33922c/lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
----------------------------------------------------------------------
diff --git 
a/lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
 
b/lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
index 49174a8..07328d3 100644
--- 
a/lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
+++ 
b/lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
@@ -65,6 +65,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
@@ -143,6 +146,7 @@ public class TestSpecificCompiler {
       assertFalse("Line started with a deprecated field declaration: " + line,
         line.startsWith("@Deprecated public int value"));
     }
+    reader.close();
   }
 
   @Test
@@ -156,6 +160,7 @@ public class TestSpecificCompiler {
     while (!foundAllArgsConstructor && (line = reader.readLine()) != null) {
       foundAllArgsConstructor = line.contains("All-args constructor");
     }
+    reader.close();
     assertTrue(foundAllArgsConstructor);
   }
 
@@ -216,6 +221,7 @@ public class TestSpecificCompiler {
       assertFalse("Line started with a public field declaration: " + line,
         line.startsWith("public int value"));
     }
+    reader.close();
   }
 
   @Test
@@ -238,6 +244,7 @@ public class TestSpecificCompiler {
       assertFalse("Line started with a deprecated field declaration: " + line,
         line.startsWith("@Deprecated public int value"));
     }
+    reader.close();
   }
 
   @Test
@@ -256,6 +263,7 @@ public class TestSpecificCompiler {
         foundSetters++;
       }
     }
+    reader.close();
     assertEquals("Found the wrong number of setters", 1, foundSetters);
   }
 
@@ -274,6 +282,7 @@ public class TestSpecificCompiler {
       assertFalse("No line should include the setter: " + line,
         line.startsWith("public void setValue("));
     }
+    reader.close();
   }
 
   @Test
@@ -282,14 +291,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/be33922c/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 557868a..eaefb12 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
@@ -412,7 +412,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/be33922c/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 589ec2a..d870e79 100644
--- a/lang/java/tools/src/test/compiler/output/Player.java
+++ b/lang/java/tools/src/test/compiler/output/Player.java
@@ -412,7 +412,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);
       }
     }

http://git-wip-us.apache.org/repos/asf/avro/blob/be33922c/share/test/schemas/specialtypes.avdl
----------------------------------------------------------------------
diff --git a/share/test/schemas/specialtypes.avdl 
b/share/test/schemas/specialtypes.avdl
index 1be3aab..062398f 100644
--- a/share/test/schemas/specialtypes.avdl
+++ b/share/test/schemas/specialtypes.avdl
@@ -103,4 +103,7 @@ protocol LetsBreakIt {
       string nl;
     }
 
+    record Exception {
+      string whatever;
+    }
 }

Reply via email to