8061778: Wrong LineNumberTable for default constructors

Fri, 24 Oct 2014 10:54:04 +0100

author
mcimadamore
date
Fri, 24 Oct 2014 10:54:04 +0100
changeset 2789
36ed04994588
parent 2788
f08330fad341
child 2790
a4bd58944aa8

8061778: Wrong LineNumberTable for default constructors
Summary: Synthetic empty blocks generated by Lower are erroneously picked up by Gen
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/comp/Lower.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/jvm/Gen.java file | annotate | diff | comparison | revisions
test/tools/javac/linenumbers/NestedLineNumberTest.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java	Fri Apr 17 08:55:59 2015 -0600
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java	Fri Oct 24 10:54:04 2014 +0100
     1.3 @@ -2540,7 +2540,7 @@
     1.4          currentMethodSym = currentMethodSymPrev;
     1.5  
     1.6          // Return empty block {} as a placeholder for an inner class.
     1.7 -        result = make_at(tree.pos()).Block(0, List.<JCStatement>nil());
     1.8 +        result = make_at(tree.pos()).Block(SYNTHETIC, List.<JCStatement>nil());
     1.9      }
    1.10  
    1.11      /** Translate an enum class. */
     2.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Fri Apr 17 08:55:59 2015 -0600
     2.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Fri Oct 24 10:54:04 2014 +0100
     2.3 @@ -486,7 +486,7 @@
     2.4                  JCBlock block = (JCBlock)def;
     2.5                  if ((block.flags & STATIC) != 0)
     2.6                      clinitCode.append(block);
     2.7 -                else
     2.8 +                else if ((block.flags & SYNTHETIC) == 0)
     2.9                      initCode.append(block);
    2.10                  break;
    2.11              case METHODDEF:
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/linenumbers/NestedLineNumberTest.java	Fri Oct 24 10:54:04 2014 +0100
     3.3 @@ -0,0 +1,81 @@
     3.4 +/*
     3.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.  Oracle designates this
    3.11 + * particular file as subject to the "Classpath" exception as provided
    3.12 + * by Oracle in the LICENSE file that accompanied this code.
    3.13 + *
    3.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.17 + * version 2 for more details (a copy is included in the LICENSE file that
    3.18 + * accompanied this code).
    3.19 + *
    3.20 + * You should have received a copy of the GNU General Public License version
    3.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.23 + *
    3.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.25 + * or visit www.oracle.com if you need additional information or have any
    3.26 + * questions.
    3.27 + */
    3.28 +
    3.29 +/*
    3.30 + * @test
    3.31 + * @bug 8061778
    3.32 + * @summary  Wrong LineNumberTable for default constructors
    3.33 + */
    3.34 +
    3.35 +import com.sun.tools.classfile.ClassFile;
    3.36 +import com.sun.tools.classfile.ConstantPoolException;
    3.37 +import com.sun.tools.classfile.Method;
    3.38 +import com.sun.tools.classfile.Attribute;
    3.39 +import com.sun.tools.classfile.Code_attribute;
    3.40 +import com.sun.tools.classfile.LineNumberTable_attribute;
    3.41 +import com.sun.tools.classfile.LineNumberTable_attribute.Entry;
    3.42 +
    3.43 +import java.io.IOException;
    3.44 +
    3.45 +public class NestedLineNumberTest {
    3.46 +
    3.47 +    public static void main(String[] args) throws Exception {
    3.48 +        Entry[] lines = findEntries();
    3.49 +        if (lines == null || lines.length != 1) {
    3.50 +            int found = lines == null ? 0 : lines.length;
    3.51 +            error(String.format("LineNumberTable contains wrong number of entries - expected %d, found %d", 1, found));
    3.52 +        }
    3.53 +
    3.54 +        int line = lines[0].line_number;
    3.55 +        if (line != 78) {
    3.56 +            error(String.format("LineNumberTable contains wrong line number - expected %d, found %d", 78, line));
    3.57 +        }
    3.58 +    }
    3.59 +
    3.60 +    static Entry[] findEntries() throws IOException, ConstantPoolException {
    3.61 +        ClassFile self = ClassFile.read(NestedLineNumberTest.Test.class.getResourceAsStream("NestedLineNumberTest$Test.class"));
    3.62 +        for (Method m : self.methods) {
    3.63 +            if ("<init>".equals(m.getName(self.constant_pool))) {
    3.64 +                Code_attribute code_attribute = (Code_attribute)m.attributes.get(Attribute.Code);
    3.65 +                for (Attribute at : code_attribute.attributes) {
    3.66 +                    if (Attribute.LineNumberTable.equals(at.getName(self.constant_pool))) {
    3.67 +                        return ((LineNumberTable_attribute)at).line_number_table;
    3.68 +                    }
    3.69 +                }
    3.70 +            }
    3.71 +        }
    3.72 +        return null;
    3.73 +    }
    3.74 +
    3.75 +    static void error(String msg) {
    3.76 +        throw new AssertionError(msg);
    3.77 +    }
    3.78 +
    3.79 +    // The default constructor in this class should get only one LineNumberTable entry,
    3.80 +    // pointing to the first line of the declaration of class Test.
    3.81 +    static class Test {
    3.82 +        static class Empty { }
    3.83 +    }
    3.84 +}

mercurial