crash with -Xjcov and union types

Liam Miller-Cushon cushon at google.com
Thu Sep 25 21:57:16 UTC 2014


I'm seeing crashes with -Xjcov enabled while compiling code with union
types. This seems to affect javac 7 through 9. I've attached a possible
fix, and a jtreg test for the crash.


Repro:


=== Test.java ===

class Test {

  void m() {

    try {

      return;

    } catch (IllegalStateException | IllegalArgumentException e) {

    }

  }

}

===


$ javac Test.java

...

An exception has occurred in the compiler (1.8.0_20). Please file a bug at
the Java Developer Connection (http://java.sun.com/webapps/bugreport)
 after checking the Bug Parade for duplicates. Include your program and the
following diagnostic in your report.  Thank you.

java.lang.AssertionError

at com.sun.tools.javac.util.Assert.error(Assert.java:126)

at
com.sun.tools.javac.jvm.CRTable$SourceComputer.visitTree(CRTable.java:529)

at com.sun.tools.javac.tree.JCTree$Visitor.visitTypeUnion(JCTree.java:2577)

...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20140925/af4c88f9/attachment-0001.html>
-------------- next part --------------
# HG changeset patch
# User cushon <cushon at google.com>
# Date 1411681109 25200
# Node ID ea73aee87ad23ecca9eb6c3133ba66807367d790
# Parent  3c7c7485fab732143c30f4bf71a7ab8411763380
Fix -Xjcov crash with union types.

diff -r 3c7c7485fab7 -r ea73aee87ad2 src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/CRTable.java
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/CRTable.java	Thu Sep 25 13:54:45 2014 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/CRTable.java	Thu Sep 25 14:38:29 2014 -0700
@@ -517,6 +517,15 @@
             result = sr;
         }
 
+        @Override
+        public void visitTypeUnion(JCTypeUnion tree) {
+            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
+            for (JCTree alternative : tree.alternatives) {
+                sr.mergeWith(csp(alternative));
+            }
+            result = sr;
+        }
+
         public void visitWildcard(JCWildcard tree) {
             result = null;
         }
diff -r 3c7c7485fab7 -r ea73aee87ad2 test/tools/javac/options/XjcovUnionType.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/options/XjcovUnionType.java	Thu Sep 25 14:38:29 2014 -0700
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 1234567
+ * @summary -Xjcov causes crash with union types
+ * @compile -Xjcov XjcovUnionType.java
+ */
+
+public class XjcovUnionType {
+  public static void main(String[] args) {
+    try {
+      return;
+    } catch (IllegalStateException | IllegalArgumentException e) {
+    }
+  }
+}


More information about the compiler-dev mailing list