Merge

Fri, 26 Jan 2018 10:16:28 -0800

author
asaha
date
Fri, 26 Jan 2018 10:16:28 -0800
changeset 3648
485d470abd63
parent 3609
fc98059c9fde
parent 3580
5804c0d89157
child 3651
d3e193687b34

Merge

.hgtags file | annotate | diff | comparison | revisions
     1.1 --- a/.hgtags	Tue Jan 09 12:43:26 2018 -0800
     1.2 +++ b/.hgtags	Fri Jan 26 10:16:28 2018 -0800
     1.3 @@ -854,4 +854,9 @@
     1.4  c18e76a704169bfdaeb498f6cb46c99251793e19 jdk8u171-b00
     1.5  64357fde9f88e1b462aaa19afff81abdcaace7bc jdk8u171-b01
     1.6  4cd77f7e459d629a2e352fc326cb56ce8fbf55bb jdk8u171-b02
     1.7 +a459065c13afe9e0e122fa232f48ba95ab23d3f5 jdk8u171-b03
     1.8 +53092d863cb60907700ac5fd7d12fc28ce871b2a jdk8u172-b00
     1.9 +47a91ecb0b875b8c03c335e11bfe5052bad4f1cf jdk8u172-b01
    1.10 +989188d1a978fea3255e733c89718b8c0b21a231 jdk8u172-b02
    1.11 +c563af72dd015eb3e528dbd121d23f0743276baa jdk8u172-b03
    1.12  a459065c13afe9e0e122fa232f48ba95ab23d3f5 jdk8u181-b00
     2.1 --- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Tue Jan 09 12:43:26 2018 -0800
     2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Fri Jan 26 10:16:28 2018 -0800
     2.3 @@ -1,5 +1,5 @@
     2.4  /*
     2.5 - * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
     2.6 + * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
     2.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.8   *
     2.9   * This code is free software; you can redistribute it and/or modify it
    2.10 @@ -2009,7 +2009,7 @@
    2.11                          Assert.error(skind.name());
    2.12                          throw new AssertionError();
    2.13                  }
    2.14 -                if (ret != sym) {
    2.15 +                if (ret != sym && skind.propagateAnnotations()) {
    2.16                      ret.setDeclarationAttributes(sym.getRawAttributes());
    2.17                      ret.setTypeAttributes(sym.getRawTypeAttributes());
    2.18                  }
    2.19 @@ -2045,7 +2045,6 @@
    2.20                              if (m.containsKey(lambdaIdent.sym)) {
    2.21                                  Symbol tSym = m.get(lambdaIdent.sym);
    2.22                                  JCTree t = make.Ident(tSym).setType(lambdaIdent.type);
    2.23 -                                tSym.setTypeAttributes(lambdaIdent.sym.getRawTypeAttributes());
    2.24                                  return t;
    2.25                              }
    2.26                              break;
    2.27 @@ -2054,7 +2053,6 @@
    2.28                                  // Transform outer instance variable references anchoring them to the captured synthetic.
    2.29                                  Symbol tSym = m.get(lambdaIdent.sym.owner);
    2.30                                  JCExpression t = make.Ident(tSym).setType(lambdaIdent.sym.owner.type);
    2.31 -                                tSym.setTypeAttributes(lambdaIdent.sym.owner.getRawTypeAttributes());
    2.32                                  t = make.Select(t, lambdaIdent.name);
    2.33                                  t.setType(lambdaIdent.type);
    2.34                                  TreeInfo.setSymbol(t, lambdaIdent.sym);
    2.35 @@ -2075,7 +2073,6 @@
    2.36                  if (m.containsKey(fieldAccess.sym.owner)) {
    2.37                      Symbol tSym = m.get(fieldAccess.sym.owner);
    2.38                      JCExpression t = make.Ident(tSym).setType(fieldAccess.sym.owner.type);
    2.39 -                    tSym.setTypeAttributes(fieldAccess.sym.owner.getRawTypeAttributes());
    2.40                      return t;
    2.41                  }
    2.42                  return null;
    2.43 @@ -2272,6 +2269,17 @@
    2.44          CAPTURED_THIS,  // class symbols to translated synthetic parameters (for captured member access)
    2.45          CAPTURED_OUTER_THIS, // used when `this' capture is illegal, but outer this capture is legit (JDK-8129740)
    2.46          TYPE_VAR;       // original to translated lambda type variables
    2.47 +
    2.48 +        boolean propagateAnnotations() {
    2.49 +            switch (this) {
    2.50 +                case CAPTURED_VAR:
    2.51 +                case CAPTURED_THIS:
    2.52 +                case CAPTURED_OUTER_THIS:
    2.53 +                    return false;
    2.54 +                default:
    2.55 +                    return true;
    2.56 +           }
    2.57 +        }
    2.58      }
    2.59  
    2.60      /**
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/annotations/typeAnnotations/classfile/TypeAnnotationPropagationTest.java	Fri Jan 26 10:16:28 2018 -0800
     3.3 @@ -0,0 +1,100 @@
     3.4 +/*
     3.5 + * Copyright (c) 2017, Google Inc. 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.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.23 + * or visit www.oracle.com if you need additional information or have any
    3.24 + * questions.
    3.25 + */
    3.26 +
    3.27 +/*
    3.28 + * @test
    3.29 + * @bug 8144185 8191969
    3.30 + * @summary javac produces incorrect RuntimeInvisibleTypeAnnotations length attribute
    3.31 + */
    3.32 +
    3.33 +import static java.lang.annotation.ElementType.TYPE_USE;
    3.34 +import static java.lang.annotation.RetentionPolicy.RUNTIME;
    3.35 +
    3.36 +import com.sun.tools.classfile.Attribute;
    3.37 +import com.sun.tools.classfile.ClassFile;
    3.38 +import com.sun.tools.classfile.Code_attribute;
    3.39 +import com.sun.tools.classfile.Method;
    3.40 +import com.sun.tools.classfile.RuntimeVisibleTypeAnnotations_attribute;
    3.41 +import com.sun.tools.classfile.TypeAnnotation;
    3.42 +import java.lang.annotation.Retention;
    3.43 +import java.lang.annotation.Target;
    3.44 +import java.util.Arrays;
    3.45 +import java.util.Objects;
    3.46 +
    3.47 +public class TypeAnnotationPropagationTest extends ClassfileTestHelper {
    3.48 +    public static void main(String[] args) throws Exception {
    3.49 +        new TypeAnnotationPropagationTest().run();
    3.50 +    }
    3.51 +
    3.52 +    public void run() throws Exception {
    3.53 +        ClassFile cf = getClassFile("TypeAnnotationPropagationTest$Test.class");
    3.54 +
    3.55 +        Method f = null;
    3.56 +        for (Method m : cf.methods) {
    3.57 +            if (m.getName(cf.constant_pool).contains("f")) {
    3.58 +                f = m;
    3.59 +                break;
    3.60 +            }
    3.61 +        }
    3.62 +
    3.63 +        int idx = f.attributes.getIndex(cf.constant_pool, Attribute.Code);
    3.64 +        Code_attribute cattr = (Code_attribute) f.attributes.get(idx);
    3.65 +        idx = cattr.attributes.getIndex(cf.constant_pool, Attribute.RuntimeVisibleTypeAnnotations);
    3.66 +        RuntimeVisibleTypeAnnotations_attribute attr =
    3.67 +                (RuntimeVisibleTypeAnnotations_attribute) cattr.attributes.get(idx);
    3.68 +
    3.69 +        TypeAnnotation anno = attr.annotations[0];
    3.70 +        assertEquals(anno.position.lvarOffset, new int[] {3}, "start_pc");
    3.71 +        assertEquals(anno.position.lvarLength, new int[] {8}, "length");
    3.72 +        assertEquals(anno.position.lvarIndex, new int[] {1}, "index");
    3.73 +    }
    3.74 +
    3.75 +    void assertEquals(int[] actual, int[] expected, String message) {
    3.76 +        if (!Arrays.equals(actual, expected)) {
    3.77 +            throw new AssertionError(
    3.78 +                    String.format(
    3.79 +                            "actual: %s, expected: %s, %s",
    3.80 +                            Arrays.toString(actual), Arrays.toString(expected), message));
    3.81 +        }
    3.82 +    }
    3.83 +
    3.84 +    /** ********************* Test class ************************ */
    3.85 +    static class Test {
    3.86 +        void f() {
    3.87 +            @A String s = "";
    3.88 +            Runnable r =
    3.89 +                    () -> {
    3.90 +                        Objects.requireNonNull(s);
    3.91 +                        Objects.requireNonNull(s);
    3.92 +                        Objects.requireNonNull(s);
    3.93 +                        Objects.requireNonNull(s);
    3.94 +                        Objects.requireNonNull(s);
    3.95 +                        Objects.requireNonNull(s);
    3.96 +                    };
    3.97 +        }
    3.98 +
    3.99 +        @Retention(RUNTIME)
   3.100 +        @Target(TYPE_USE)
   3.101 +        @interface A {}
   3.102 +    }
   3.103 +}

mercurial