Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id DE207200C0A for ; Sat, 28 Jan 2017 11:10:57 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id DCA64160B51; Sat, 28 Jan 2017 10:10:57 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 0D8D5160B35 for ; Sat, 28 Jan 2017 11:10:56 +0100 (CET) Received: (qmail 43197 invoked by uid 500); 28 Jan 2017 10:10:56 -0000 Mailing-List: contact commits-help@avro.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@avro.apache.org Delivered-To: mailing list commits@avro.apache.org Received: (qmail 43188 invoked by uid 99); 28 Jan 2017 10:10:56 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 28 Jan 2017 10:10:56 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 09D73DFBE6; Sat, 28 Jan 2017 10:10:55 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: busbey@apache.org To: commits@avro.apache.org Message-Id: <7681f859af734592ad1019bb16334261@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: avro git commit: AVRO-1901: Record named Exception generated bad code Date: Sat, 28 Jan 2017 10:10:56 +0000 (UTC) archived-at: Sat, 28 Jan 2017 10:10:58 -0000 Repository: avro Updated Branches: refs/heads/branch-1.7 49f3bf03d -> 3345e1323 AVRO-1901: Record named Exception generated bad code Amending-Author: Ben McCann 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 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 Authored: Fri Jan 13 15:22:57 2017 -0800 Committer: Sean Busbey 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) 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) defaultValue(fields()[3]); return record; - } catch (Exception e) { + } catch (java.lang.Exception e) { throw new org.apache.avro.AvroRuntimeException(e); } }