# HG changeset patch # User lana # Date 1430439688 25200 # Node ID 1bffa0091f27e0f09e4cb2997dd21970a4f4f751 # Parent 6a2f534a9c4ba3860cdecc4ec7634293606b2699# Parent 5686d5e44a83ce5683f500260a459c312fe79697 Merge diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java Thu Apr 30 13:02:09 2015 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java Thu Apr 30 17:21:28 2015 -0700 @@ -128,7 +128,7 @@ * the completer to be used for ".java" files. If this remains unassigned * ".java" files will not be loaded. */ - public Completer sourceCompleter = null; + public Completer sourceCompleter = Completer.NULL_COMPLETER; /** The path name of the class file currently being read. */ @@ -341,7 +341,7 @@ reader.readClassFile(c); c.flags_field |= getSupplementaryFlags(c); } else { - if (sourceCompleter != null) { + if (!sourceCompleter.isTerminal()) { sourceCompleter.complete(c); } else { throw new IllegalStateException("Source completer required to read " @@ -392,7 +392,7 @@ public ClassSymbol loadClass(Name flatname) throws CompletionFailure { boolean absent = syms.classes.get(flatname) == null; ClassSymbol c = syms.enterClass(flatname); - if (c.members_field == null && c.completer != null) { + if (c.members_field == null) { try { c.complete(); } catch (CompletionFailure ex) { diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java Thu Apr 30 13:02:09 2015 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java Thu Apr 30 17:21:28 2015 -0700 @@ -96,6 +96,7 @@ public Symbol owner; /** The completer of this symbol. + * This should never equal null (NULL_COMPLETER should be used instead). */ public Completer completer; @@ -193,6 +194,10 @@ return (metadata != null && !metadata.isTypesEmpty()); } + public boolean isCompleted() { + return completer.isTerminal(); + } + public void prependAttributes(List l) { if (l.nonEmpty()) { initedMetadata().prepend(l); @@ -243,7 +248,7 @@ this.flags_field = flags; this.type = type; this.owner = owner; - this.completer = null; + this.completer = Completer.NULL_COMPLETER; this.erasure_field = null; this.name = name; } @@ -568,9 +573,9 @@ /** Complete the elaboration of this symbol's definition. */ public void complete() throws CompletionFailure { - if (completer != null) { + if (completer != Completer.NULL_COMPLETER) { Completer c = completer; - completer = null; + completer = Completer.NULL_COMPLETER; c.complete(this); } } @@ -872,19 +877,19 @@ } public WriteableScope members() { - if (completer != null) complete(); + complete(); return members_field; } public long flags() { - if (completer != null) complete(); + complete(); return flags_field; } @Override public List getRawAttributes() { - if (completer != null) complete(); - if (package_info != null && package_info.completer != null) { + complete(); + if (package_info != null) { package_info.complete(); mergeAttributes(); } @@ -1000,24 +1005,24 @@ } public long flags() { - if (completer != null) complete(); + complete(); return flags_field; } public WriteableScope members() { - if (completer != null) complete(); + complete(); return members_field; } @Override public List getRawAttributes() { - if (completer != null) complete(); + complete(); return super.getRawAttributes(); } @Override public List getRawTypeAttributes() { - if (completer != null) complete(); + complete(); return super.getRawTypeAttributes(); } @@ -1782,7 +1787,29 @@ /** Symbol completer interface. */ public static interface Completer { + + /** Dummy completer to be used when the symbol has been completed or + * does not need completion. + */ + public final static Completer NULL_COMPLETER = new Completer() { + public void complete(Symbol sym) { } + public boolean isTerminal() { return true; } + }; + void complete(Symbol sym) throws CompletionFailure; + + /** Returns true if this completer is terminal. A terminal + * completer is used as a place holder when the symbol is completed. + * Calling complete on a terminal completer will not affect the symbol. + * + * The dummy NULL_COMPLETER and the GraphDependencies completer are + * examples of terminal completers. + * + * @return true iff this completer is terminal + */ + default boolean isTerminal() { + return false; + } } public static class CompletionFailure extends RuntimeException { diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java Thu Apr 30 13:02:09 2015 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java Thu Apr 30 17:21:28 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, 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 @@ -259,49 +259,54 @@ public void synthesizeEmptyInterfaceIfMissing(final Type type) { final Completer completer = type.tsym.completer; - if (completer != null) { - type.tsym.completer = new Completer() { - public void complete(Symbol sym) throws CompletionFailure { - try { - completer.complete(sym); - } catch (CompletionFailure e) { - sym.flags_field |= (PUBLIC | INTERFACE); - ((ClassType) sym.type).supertype_field = objectType; - } + type.tsym.completer = new Completer() { + public void complete(Symbol sym) throws CompletionFailure { + try { + completer.complete(sym); + } catch (CompletionFailure e) { + sym.flags_field |= (PUBLIC | INTERFACE); + ((ClassType) sym.type).supertype_field = objectType; } - }; - } + } + + @Override + public boolean isTerminal() { + return completer.isTerminal(); + } + }; } public void synthesizeBoxTypeIfMissing(final Type type) { ClassSymbol sym = enterClass(boxedName[type.getTag().ordinal()]); final Completer completer = sym.completer; - if (completer != null) { - sym.completer = new Completer() { - public void complete(Symbol sym) throws CompletionFailure { - try { - completer.complete(sym); - } catch (CompletionFailure e) { - sym.flags_field |= PUBLIC; - ((ClassType) sym.type).supertype_field = objectType; - MethodSymbol boxMethod = - new MethodSymbol(PUBLIC | STATIC, names.valueOf, - new MethodType(List.of(type), sym.type, - List.nil(), methodClass), - sym); - sym.members().enter(boxMethod); - MethodSymbol unboxMethod = - new MethodSymbol(PUBLIC, - type.tsym.name.append(names.Value), // x.intValue() - new MethodType(List.nil(), type, - List.nil(), methodClass), - sym); - sym.members().enter(unboxMethod); - } + sym.completer = new Completer() { + public void complete(Symbol sym) throws CompletionFailure { + try { + completer.complete(sym); + } catch (CompletionFailure e) { + sym.flags_field |= PUBLIC; + ((ClassType) sym.type).supertype_field = objectType; + MethodSymbol boxMethod = + new MethodSymbol(PUBLIC | STATIC, names.valueOf, + new MethodType(List.of(type), sym.type, + List.nil(), methodClass), + sym); + sym.members().enter(boxMethod); + MethodSymbol unboxMethod = + new MethodSymbol(PUBLIC, + type.tsym.name.append(names.Value), // x.intValue() + new MethodType(List.nil(), type, + List.nil(), methodClass), + sym); + sym.members().enter(unboxMethod); } - }; - } + } + @Override + public boolean isTerminal() { + return completer.isTerminal(); + } + }; } // Enter a synthetic class that is used to mark classes in ct.sym. @@ -309,7 +314,7 @@ private Type enterSyntheticAnnotation(String name) { ClassType type = (ClassType)enterClass(name); ClassSymbol sym = (ClassSymbol)type.tsym; - sym.completer = null; + sym.completer = Completer.NULL_COMPLETER; sym.flags_field = PUBLIC|ACYCLIC|ANNOTATION|INTERFACE; sym.erasure_field = type; sym.members_field = WriteableScope.create(sym); diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Type.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Type.java Thu Apr 30 13:02:09 2015 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Type.java Thu Apr 30 17:21:28 2015 -0700 @@ -580,12 +580,10 @@ } public boolean isCompound() { - return tsym.completer == null - // Compound types can't have a completer. Calling - // flags() will complete the symbol causing the - // compiler to load classes unnecessarily. This led - // to regression 6180021. - && (tsym.flags() & COMPOUND) != 0; + // Compound types can't have a (non-terminal) completer. Calling + // flags() will complete the symbol causing the compiler to load + // classes unnecessarily. This led to regression 6180021. + return tsym.isCompleted() && (tsym.flags() & COMPOUND) != 0; } public boolean isIntersection() { @@ -1124,7 +1122,7 @@ } public void complete() { - if (tsym.completer != null) tsym.complete(); + tsym.complete(); } @DefinedBy(Api.LANGUAGE_MODEL) @@ -1212,7 +1210,7 @@ Assert.check((csym.flags() & COMPOUND) != 0); supertype_field = bounds.head; interfaces_field = bounds.tail; - Assert.check(supertype_field.tsym.completer != null || + Assert.check(!supertype_field.tsym.isCompleted() || !supertype_field.isInterface(), supertype_field); } diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotations.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Thu Apr 30 13:02:09 2015 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Thu Apr 30 17:21:28 2015 -0700 @@ -28,11 +28,11 @@ import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.type.TypeKind; - import javax.tools.JavaFileObject; import com.sun.tools.javac.code.Attribute.Array; import com.sun.tools.javac.code.Attribute.TypeCompound; +import com.sun.tools.javac.code.Symbol.TypeSymbol; import com.sun.tools.javac.code.Type.ArrayType; import com.sun.tools.javac.code.Type.CapturedType; import com.sun.tools.javac.code.Type.ClassType; @@ -153,8 +153,8 @@ public enum AnnotationType { DECLARATION, TYPE, NONE, BOTH } - public List annotationTargets(Attribute.Compound anno) { - Attribute.Compound atTarget = anno.type.tsym.getAnnotationTypeMetadata().getTarget(); + public List annotationTargets(TypeSymbol tsym) { + Attribute.Compound atTarget = tsym.getAnnotationTypeMetadata().getTarget(); if (atTarget == null) { return null; } @@ -177,7 +177,7 @@ * a type annotation, or both. */ public AnnotationType annotationTargetType(Attribute.Compound a, Symbol s) { - List targets = annotationTargets(a); + List targets = annotationTargets(a.type.tsym); return (targets == null) ? AnnotationType.DECLARATION : targets.stream() diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java Thu Apr 30 13:02:09 2015 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java Thu Apr 30 17:21:28 2015 -0700 @@ -645,7 +645,7 @@ Symbol descSym = findDescriptorSymbol(targets.head.tsym); Type descType = findDescriptorType(targets.head); ClassSymbol csym = new ClassSymbol(cflags, name, env.enclClass.sym.outermostClass()); - csym.completer = null; + csym.completer = Completer.NULL_COMPLETER; csym.members_field = WriteableScope.create(csym); MethodSymbol instDescSym = new MethodSymbol(descSym.flags(), descSym.name, descType, csym); csym.members_field.enter(instDescSym); diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java Thu Apr 30 13:02:09 2015 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java Thu Apr 30 17:21:28 2015 -0700 @@ -243,7 +243,10 @@ log.error(annotations.head.pos, "already.annotated", Kinds.kindName(s), s); Assert.checkNonNull(s, "Symbol argument to actualEnterAnnotations is null"); - annotateNow(s, annotations, localEnv, false); + + // false is passed as fifth parameter since annotateLater is + // never called for a type parameter + annotateNow(s, annotations, localEnv, false, false); } finally { if (prevLint != null) chk.setLint(prevLint); @@ -327,7 +330,8 @@ * then continue on with repeating annotations processing. */ private void annotateNow(Symbol toAnnotate, - List withAnnotations, Env env, boolean typeAnnotations) + List withAnnotations, Env env, boolean typeAnnotations, + boolean isTypeParam) { Map> annotated = new LinkedHashMap<>(); Map pos = new HashMap<>(); @@ -377,7 +381,7 @@ buf = buf.prepend(lb.first()); } else { AnnotationContext ctx = new AnnotationContext<>(env, annotated, pos, typeAnnotations); - T res = makeContainerAnnotation(lb.toList(), ctx, toAnnotate); + T res = makeContainerAnnotation(lb.toList(), ctx, toAnnotate, isTypeParam); if (res != null) buf = buf.prepend(res); } @@ -698,7 +702,7 @@ * annotation are invalid. This method reports errors/warnings. */ private T processRepeatedAnnotations(List annotations, - AnnotationContext ctx, Symbol on) + AnnotationContext ctx, Symbol on, boolean isTypeParam) { T firstOccurrence = annotations.head; List repeated = List.nil(); @@ -752,7 +756,8 @@ if (!repeated.isEmpty()) { repeated = repeated.reverse(); - TreeMaker m = make.at(ctx.pos.get(firstOccurrence)); + DiagnosticPosition pos = ctx.pos.get(firstOccurrence); + TreeMaker m = make.at(pos); Pair p = new Pair(containerValueSymbol, new Attribute.Array(arrayOfOrigAnnoType, repeated)); @@ -768,7 +773,14 @@ Attribute.TypeCompound at = new Attribute.TypeCompound(targetContainerType, List.of(p), ((Attribute.TypeCompound)annotations.head).position); - // TODO: annotation applicability checks from below? + JCAnnotation annoTree = m.TypeAnnotation(at); + if (!chk.validateAnnotationDeferErrors(annoTree)) + log.error(annoTree.pos(), Errors.DuplicateAnnotationInvalidRepeated(origAnnoType)); + + if (!chk.isTypeAnnotation(annoTree, isTypeParam)) { + log.error(pos, isTypeParam ? Errors.InvalidRepeatableAnnotationNotApplicable(targetContainerType, on) + : Errors.InvalidRepeatableAnnotationNotApplicableInContext(targetContainerType)); + } at.setSynthesized(true); @@ -925,11 +937,11 @@ } private T makeContainerAnnotation(List toBeReplaced, - AnnotationContext ctx, Symbol sym) + AnnotationContext ctx, Symbol sym, boolean isTypeParam) { // Process repeated annotations T validRepeated = - processRepeatedAnnotations(toBeReplaced, ctx, sym); + processRepeatedAnnotations(toBeReplaced, ctx, sym, isTypeParam); if (validRepeated != null) { // Check that the container isn't manually @@ -955,7 +967,7 @@ * Attribute the list of annotations and enter them onto s. */ public void enterTypeAnnotations(List annotations, Env env, - Symbol s, DiagnosticPosition deferPos) + Symbol s, DiagnosticPosition deferPos, boolean isTypeParam) { Assert.checkNonNull(s, "Symbol argument to actualEnterTypeAnnotations is nul/"); JavaFileObject prev = log.useSource(env.toplevel.sourcefile); @@ -965,7 +977,7 @@ prevLintPos = deferredLintHandler.setPos(deferPos); } try { - annotateNow(s, annotations, env, true); + annotateNow(s, annotations, env, true, isTypeParam); } finally { if (prevLintPos != null) deferredLintHandler.setPos(prevLintPos); @@ -1048,21 +1060,21 @@ @Override public void visitAnnotatedType(JCAnnotatedType tree) { - enterTypeAnnotations(tree.annotations, env, sym, deferPos); + enterTypeAnnotations(tree.annotations, env, sym, deferPos, false); scan(tree.underlyingType); } @Override public void visitTypeParameter(JCTypeParameter tree) { - enterTypeAnnotations(tree.annotations, env, sym, deferPos); + enterTypeAnnotations(tree.annotations, env, sym, deferPos, true); scan(tree.bounds); } @Override public void visitNewArray(JCNewArray tree) { - enterTypeAnnotations(tree.annotations, env, sym, deferPos); + enterTypeAnnotations(tree.annotations, env, sym, deferPos, false); for (List dimAnnos : tree.dimAnnotations) - enterTypeAnnotations(dimAnnos, env, sym, deferPos); + enterTypeAnnotations(dimAnnos, env, sym, deferPos, false); scan(tree.elemtype); scan(tree.elems); } @@ -1241,7 +1253,7 @@ private void init() { // Make sure metaDataFor is member entered - while (metaDataFor.completer != null) + while (!metaDataFor.isCompleted()) metaDataFor.complete(); if (annotationTypeCompleter != null) { diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java Thu Apr 30 13:02:09 2015 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java Thu Apr 30 17:21:28 2015 -0700 @@ -2425,6 +2425,11 @@ resultInfo.checkContext.report(that, cause); result = that.type = types.createErrorType(pt()); return; + } catch (Throwable t) { + //when an unexpected exception happens, avoid attempts to attribute the same tree again + //as that would likely cause the same exception again. + needsRecovery = false; + throw t; } finally { localEnv.info.scope.leave(); if (needsRecovery) { diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java Thu Apr 30 13:02:09 2015 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java Thu Apr 30 17:21:28 2015 -0700 @@ -2268,7 +2268,7 @@ } } if (complete) - complete = ((c.flags_field & UNATTRIBUTED) == 0) && c.completer == null; + complete = ((c.flags_field & UNATTRIBUTED) == 0) && c.isCompleted(); if (complete) c.flags_field |= ACYCLIC; return complete; } @@ -2999,7 +2999,7 @@ /** Is the annotation applicable to types? */ protected boolean isTypeAnnotation(JCAnnotation a, boolean isTypeParameter) { - List targets = typeAnnotations.annotationTargets(a.attribute); + List targets = typeAnnotations.annotationTargets(a.annotationType.type.tsym); return (targets == null) ? false : targets.stream() diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java Thu Apr 30 13:02:09 2015 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java Thu Apr 30 17:21:28 2015 -0700 @@ -320,7 +320,7 @@ ClassSymbol c = syms.enterClass(name, tree.packge); c.flatname = names.fromString(tree.packge + "." + name); c.sourcefile = tree.sourcefile; - c.completer = null; + c.completer = Completer.NULL_COMPLETER; c.members_field = WriteableScope.create(c); tree.packge.package_info = c; } @@ -386,7 +386,7 @@ typeEnvs.put(c, localEnv); // Fill out class fields. - c.completer = null; // do not allow the initial completer linger on. + c.completer = Completer.NULL_COMPLETER; // do not allow the initial completer linger on. c.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, c, tree); c.sourcefile = env.toplevel.sourcefile; c.members_field = WriteableScope.create(c); diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java Thu Apr 30 13:02:09 2015 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java Thu Apr 30 17:21:28 2015 -0700 @@ -641,7 +641,7 @@ c.flatname = chk.localClassName(c); } c.sourcefile = owner.sourcefile; - c.completer = null; + c.completer = Completer.NULL_COMPLETER; c.members_field = WriteableScope.create(c); c.flags_field = flags; ClassType ctype = (ClassType) c.type; diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java Thu Apr 30 13:02:09 2015 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java Thu Apr 30 17:21:28 2015 -0700 @@ -25,6 +25,9 @@ package com.sun.tools.javac.comp; +import java.util.EnumSet; +import java.util.Set; + import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Scope.WriteableScope; import com.sun.tools.javac.tree.*; @@ -335,43 +338,49 @@ return initTreeVisitor.result; } - /** Visitor class for expressions which might be constant expressions. + /** Visitor class for expressions which might be constant expressions, + * as per JLS 15.28 (Constant Expressions). */ static class InitTreeVisitor extends JCTree.Visitor { + private static final Set ALLOWED_OPERATORS = + EnumSet.of(Tag.POS, Tag.NEG, Tag.NOT, Tag.COMPL, Tag.PLUS, Tag.MINUS, + Tag.MUL, Tag.DIV, Tag.MOD, Tag.SL, Tag.SR, Tag.USR, + Tag.LT, Tag.LE, Tag.GT, Tag.GE, Tag.EQ, Tag.NE, + Tag.BITAND, Tag.BITXOR, Tag.BITOR, Tag.AND, Tag.OR); + private boolean result = true; @Override - public void visitTree(JCTree tree) {} - - @Override - public void visitNewClass(JCNewClass that) { + public void visitTree(JCTree tree) { result = false; } @Override - public void visitNewArray(JCNewArray that) { - result = false; - } + public void visitLiteral(JCLiteral that) {} @Override - public void visitLambda(JCLambda that) { - result = false; + public void visitTypeCast(JCTypeCast tree) { + tree.expr.accept(this); } @Override - public void visitReference(JCMemberReference that) { - result = false; + public void visitUnary(JCUnary that) { + if (!ALLOWED_OPERATORS.contains(that.getTag())) { + result = false; + return ; + } + that.arg.accept(this); } @Override - public void visitApply(JCMethodInvocation that) { - result = false; - } - - @Override - public void visitSelect(JCFieldAccess tree) { - tree.selected.accept(this); + public void visitBinary(JCBinary that) { + if (!ALLOWED_OPERATORS.contains(that.getTag())) { + result = false; + return ; + } + that.lhs.accept(this); + that.rhs.accept(this); } @Override @@ -387,8 +396,11 @@ } @Override - public void visitTypeCast(JCTypeCast tree) { - tree.expr.accept(this); + public void visitIdent(JCIdent that) {} + + @Override + public void visitSelect(JCFieldAccess tree) { + tree.selected.accept(this); } } diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java Thu Apr 30 13:02:09 2015 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java Thu Apr 30 17:21:28 2015 -0700 @@ -903,7 +903,7 @@ memberEnter.memberEnter(tree.defs, env); if (tree.sym.isAnnotationType()) { - Assert.checkNull(tree.sym.completer); + Assert.check(tree.sym.isCompleted()); tree.sym.setAnnotationTypeMetadata(new AnnotationTypeMetadata(tree.sym, annotate.annotationTypeSourceCompleter())); } } diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Thu Apr 30 13:02:09 2015 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Thu Apr 30 17:21:28 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -1092,7 +1092,7 @@ if (cs.classfile != null || cs.kind == ERR) { cs.reset(); cs.type = new ClassType(cs.type.getEnclosingType(), null, cs); - if (cs.completer == null) { + if (cs.isCompleted()) { cs.completer = initialCompleter; } } diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Apr 30 13:02:09 2015 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Apr 30 17:21:28 2015 -0700 @@ -414,6 +414,10 @@ compiler.err.invalid.repeatable.annotation.not.applicable=\ container {0} is not applicable to element {1} +# 0: type +compiler.err.invalid.repeatable.annotation.not.applicable.in.context=\ + container {0} is not applicable in this type context + # 0: name compiler.err.duplicate.class=\ duplicate class: {0} diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Dependencies.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Dependencies.java Thu Apr 30 13:02:09 2015 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Dependencies.java Thu Apr 30 17:21:28 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, 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 @@ -468,6 +468,11 @@ sym.completer = this; } + @Override + public boolean isTerminal() { + return true; + } + /** * This visitor is used to generate the special side-effect dependencies * given a graph containing only standard dependencies. diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/ClassDocImpl.java --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/ClassDocImpl.java Thu Apr 30 13:02:09 2015 -0700 +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/ClassDocImpl.java Thu Apr 30 17:21:28 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -796,9 +796,7 @@ } // make sure that this symbol has been completed - if (tsym.completer != null) { - tsym.complete(); - } + tsym.complete(); // search imports diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/JavadocTool.java --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/JavadocTool.java Thu Apr 30 13:02:09 2015 -0700 +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/JavadocTool.java Thu Apr 30 17:21:28 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -40,6 +40,7 @@ import javax.tools.StandardLocation; import com.sun.tools.javac.code.ClassFinder; +import com.sun.tools.javac.code.Symbol.Completer; import com.sun.tools.javac.code.Symbol.CompletionFailure; import com.sun.tools.javac.comp.Enter; import com.sun.tools.javac.tree.JCTree; @@ -141,7 +142,7 @@ docenv.docClasses = docClasses; docenv.legacyDoclet = legacyDoclet; - javadocFinder.sourceCompleter = docClasses ? null : sourceCompleter; + javadocFinder.sourceCompleter = docClasses ? Completer.NULL_COMPLETER : sourceCompleter; ListBuffer names = new ListBuffer<>(); ListBuffer classTrees = new ListBuffer<>(); diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/Paths/wcMineField.sh --- a/langtools/test/tools/javac/Paths/wcMineField.sh Thu Apr 30 13:02:09 2015 -0700 +++ b/langtools/test/tools/javac/Paths/wcMineField.sh Thu Apr 30 17:21:28 2015 -0700 @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2005, 2015, 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 @@ -49,9 +49,9 @@ #---------------------------------------------------------------- Cleanup() { Sys rm -rf GooSrc GooJar GooZip GooClass - Sys rm -rf SpeSrc SpeJar SpeZip SpeClass + Sys rm -rf SpeSrc SpeJar SpeZip SpeClass Sys rm -rf BadSrc BadJar BadZip BadClass - Sys rm -rf JarNClass StarJar MixJar StarDir + Sys rm -rf JarNClass StarJar MixJar StarDir Sys rm -rf OneDir *.class Main*.java MANIFEST.MF } @@ -127,11 +127,9 @@ printf "Running tests with directory named \"*\"\n" Sys rm -rf ./StarDir Sys mkdir -p StarDir/"*" - Sys cp -p "GooClass/Lib3.class" "GooClass/Lib.class" ./ Sys cp "GooClass/Lib2.class" "StarDir/*/Lib2.class" - Sys "$jar" cf "StarDir/Lib3.jar" "Lib3.class" - Sys "$jar" cf "StarDir/*/Lib.jar" "Lib.class" - Sys rm -f "./Lib.class" "./Lib3.class" + Sys "$jar" cf "StarDir/Lib3.jar" -C GooClass "Lib3.class" + Sys "$jar" cf "StarDir/*/Lib.jar" -C GooClass "Lib.class" CheckFiles "StarDir/*/Lib.jar" "StarDir/*/Lib2.class" "StarDir/Lib3.jar" Sys cp Main6.java ./StarDir/. Sys cp Main.java ./StarDir/"*"/. diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/annotations/repeatingAnnotations/InvalidClsTypeParamTarget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/InvalidClsTypeParamTarget.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,21 @@ +/** + * @test /nodynamiccopyright/ + * @bug 8044196 + * @summary Ensure that containers with target FIELD can't be applied to type parameters. + * @compile/fail/ref=InvalidClsTypeParamTarget.out -XDrawDiagnostics InvalidClsTypeParamTarget.java + */ + +import java.lang.annotation.*; + +class InvalidClsTypeParamTarget { + + @Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE, ElementType.FIELD}) + @Repeatable(TC.class) + @interface T { int value(); } + + @Target(ElementType.FIELD) + @interface TC { T[] value(); } + + class Test<@T(1) @T(2) N> { + } +} diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/annotations/repeatingAnnotations/InvalidClsTypeParamTarget.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/InvalidClsTypeParamTarget.out Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,2 @@ +InvalidClsTypeParamTarget.java:19:16: compiler.err.invalid.repeatable.annotation.not.applicable: InvalidClsTypeParamTarget.TC, InvalidClsTypeParamTarget.Test +1 error diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/annotations/repeatingAnnotations/InvalidMethodTypeParamTarget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/InvalidMethodTypeParamTarget.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,20 @@ +/** + * @test /nodynamiccopyright/ + * @bug 8044196 + * @summary Ensure that containers with target METHOD can't be applied to type parameters. + * @compile/fail/ref=InvalidMethodTypeParamTarget.out -XDrawDiagnostics InvalidMethodTypeParamTarget.java + */ + +import java.lang.annotation.*; + +class InvalidMethodTypeParamTarget { + + @Target({ElementType.TYPE_PARAMETER, ElementType.METHOD}) + @Repeatable(TC.class) + @interface T { int value(); } + + @Target(ElementType.METHOD) + @interface TC { T[] value(); } + + public <@T(1) @T(2) N> void method() { } +} diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/annotations/repeatingAnnotations/InvalidMethodTypeParamTarget.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/InvalidMethodTypeParamTarget.out Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,2 @@ +InvalidMethodTypeParamTarget.java:19:13: compiler.err.invalid.repeatable.annotation.not.applicable: InvalidMethodTypeParamTarget.TC, method() +1 error diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/annotations/repeatingAnnotations/InvalidMethodTypeUse.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/InvalidMethodTypeUse.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,24 @@ +/** + * @test /nodynamiccopyright/ + * @bug 8044196 + * @summary Make sure repeatable annotations can't be erroneously applied to type arguments. + * @compile/fail/ref=InvalidMethodTypeUse.out -XDrawDiagnostics InvalidMethodTypeUse.java + */ + +import java.lang.annotation.*; + +class InvalidMethodTypeUse { + + @Target({ElementType.TYPE_USE, ElementType.METHOD, ElementType.TYPE_PARAMETER}) + @Repeatable(TC.class) + @interface T { int value(); } + + @Target({ElementType.METHOD, ElementType.TYPE_PARAMETER}) + @interface TC { T[] value(); } + + void method() { + this.<@T(1) @T(2) String>method2(); + } + + <@T(3) S> void method2() { } +} diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/annotations/repeatingAnnotations/InvalidMethodTypeUse.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/InvalidMethodTypeUse.out Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,2 @@ +InvalidMethodTypeUse.java:20:15: compiler.err.invalid.repeatable.annotation.not.applicable.in.context: InvalidMethodTypeUse.TC +1 error diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/annotations/repeatingAnnotations/InvalidRepAnnoOnCast.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/InvalidRepAnnoOnCast.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,20 @@ +/** + * @test /nodynamiccopyright/ + * @bug 8044196 + * @summary Make sure repeatable annotations can't be erroneously applied to a cast type + * @compile/fail/ref=InvalidRepAnnoOnCast.out -XDrawDiagnostics InvalidRepAnnoOnCast.java + */ + +import java.lang.annotation.*; + +class InvalidRepAnnoOnCast { + + @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) + @Repeatable(TC.class) + @interface T { int value(); } + + @Target(ElementType.TYPE_PARAMETER) + @interface TC { T[] value(); } + + String s = (@T(1) @T(2) String) new Object(); +} diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/annotations/repeatingAnnotations/InvalidRepAnnoOnCast.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/InvalidRepAnnoOnCast.out Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,2 @@ +InvalidRepAnnoOnCast.java:19:17: compiler.err.invalid.repeatable.annotation.not.applicable.in.context: InvalidRepAnnoOnCast.TC +1 error diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/annotations/repeatingAnnotations/brokenTypeAnnoContainer/BrokenTypeAnnoContainer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/brokenTypeAnnoContainer/BrokenTypeAnnoContainer.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,14 @@ +/** + * @test /nodynamiccopyright/ + * @bug 8044196 + * @summary Ensure that a broken type annotation container generates a correct error message. + * @compile T.java TC.java + * @compile TCBroken.java + * @compile/fail/ref=BrokenTypeAnnoContainer.out -XDrawDiagnostics BrokenTypeAnnoContainer.java + */ + +class BrokenTypeAnnoContainer { + void method() { + int ll2 = (@T(1) @T(2) int) 0; + } +} diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/annotations/repeatingAnnotations/brokenTypeAnnoContainer/BrokenTypeAnnoContainer.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/brokenTypeAnnoContainer/BrokenTypeAnnoContainer.out Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,2 @@ +BrokenTypeAnnoContainer.java:12:20: compiler.err.duplicate.annotation.invalid.repeated: T +1 error diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/annotations/repeatingAnnotations/brokenTypeAnnoContainer/T.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/brokenTypeAnnoContainer/T.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2015, 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. + */ + +import java.lang.annotation.*; + +@Target(ElementType.TYPE_USE) +@Repeatable(TC.class) +@interface T { int value(); } diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/annotations/repeatingAnnotations/brokenTypeAnnoContainer/TC.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/brokenTypeAnnoContainer/TC.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2015, 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. + */ + +import java.lang.annotation.*; + +@Target(ElementType.TYPE_USE) +@interface TC { + T[] value(); +} + diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/annotations/repeatingAnnotations/brokenTypeAnnoContainer/TCBroken.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/brokenTypeAnnoContainer/TCBroken.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2015, 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. + */ + +import java.lang.annotation.*; + +@Target(ElementType.TYPE_USE) +@interface TC { + T[] value(); + int foo(); +} diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/classfiles/attributes/Synthetic/AccessToPrivateInnerClassMembersTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Synthetic/AccessToPrivateInnerClassMembersTest.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2015, 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 8044537 + * @summary Checking ACC_SYNTHETIC flag is generated for access method +* generated to access to private methods and fields. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build AccessToPrivateInnerClassMembersTest SyntheticTestDriver ExpectedClass ExpectedClasses + * @run main SyntheticTestDriver AccessToPrivateInnerClassMembersTest 1 + */ + +/** + * Access from top level class to inner classes. + * Synthetic members: + * 1. inner classes for Inner*. + * 2. getter/setter for private field var. + * 3. access method for private method function(). + * 4. getter/setter for private field staticVar. + * 5. access method for private method staticFunction(). + * 6. field this in Inner1. + * 7. constructor for Inner*. + */ +@ExpectedClass(className = "AccessToPrivateInnerClassMembersTest", + expectedMethods = {"()", "()"}) +@ExpectedClass(className = "AccessToPrivateInnerClassMembersTest$Inner1", + expectedMethods = {"(AccessToPrivateInnerClassMembersTest)", "function()"}, + expectedFields = "var", + expectedNumberOfSyntheticMethods = 4, + expectedNumberOfSyntheticFields = 1) +@ExpectedClass(className = "AccessToPrivateInnerClassMembersTest$Inner2", + expectedMethods = {"function()", "staticFunction()", "()"}, + expectedFields = {"staticVar", "var"}, + expectedNumberOfSyntheticMethods = 7) +public class AccessToPrivateInnerClassMembersTest { + + private class Inner1 { + private Inner1() {} + private int var; + private void function() {} + } + + { + Inner1 inner = new Inner1(); + inner.var = 0; + int i = inner.var; + inner.function(); + } + + private static class Inner2 { + private Inner2() {} + private int var; + private static int staticVar; + private void function() {} + private static void staticFunction() {} + } + + { + Inner2 inner = new Inner2(); + inner.var = 0; + int i = inner.var; + inner.function(); + } + + static { + Inner2.staticFunction(); + Inner2.staticVar = 0; + int i = Inner2.staticVar; + } +} diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/classfiles/attributes/Synthetic/AccessToPrivateSiblingsTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Synthetic/AccessToPrivateSiblingsTest.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2015, 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 8044537 + * @summary Checking ACC_SYNTHETIC flag is generated for access method + * generated to access to private methods and fields. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build AccessToPrivateSiblingsTest SyntheticTestDriver ExpectedClass ExpectedClasses + * @run main SyntheticTestDriver AccessToPrivateSiblingsTest 1 + */ + +/** + * Access from sibling classes to sibling classes. + * Synthetic members: + * 1. inner classes for Inner*. + * 2. getter/setter for private field var. + * 3. access method for private method function(). + * 4. getter/setter for private field staticVar. + * 5. access method for private method staticFunction(). + * 6. field this in Inner1. + * 7. constructor for Inner*. + */ +@ExpectedClass(className = "AccessToPrivateSiblingsTest", expectedMethods = "()") +@ExpectedClass(className = "AccessToPrivateSiblingsTest$Inner1", + expectedMethods = {"function()", "(AccessToPrivateSiblingsTest)"}, + expectedFields = "var", + expectedNumberOfSyntheticMethods = 4, + expectedNumberOfSyntheticFields = 1) +@ExpectedClass(className = "AccessToPrivateSiblingsTest$Inner2", + expectedMethods = "(AccessToPrivateSiblingsTest)", + expectedNumberOfSyntheticFields = 1) +@ExpectedClass(className = "AccessToPrivateSiblingsTest$Inner3", + expectedMethods = {"()", "function()", "staticFunction()", "()"}, + expectedFields = {"var", "staticVar"}, + expectedNumberOfSyntheticMethods = 4) +@ExpectedClass(className = "AccessToPrivateSiblingsTest$Inner4", + expectedMethods = {"()", "function()", "staticFunction()"}, + expectedFields = {"var", "staticVar"}, + expectedNumberOfSyntheticMethods = 4) +public class AccessToPrivateSiblingsTest { + + private class Inner1 { + private Inner1() {} + private int var; + private void function() {} + + { + Inner3 inner = new Inner3(); + inner.var = 0; + int i = inner.var; + inner.function(); + } + } + + private class Inner2 { + { + Inner1 inner = new Inner1(); + inner.var = 0; + int i = inner.var; + inner.function(); + } + } + + private static class Inner3 { + private Inner3() {} + private int var; + private static int staticVar; + private void function() {} + private static void staticFunction() {} + + static { + Inner4 inner = new Inner4(); + inner.var = 0; + int i = inner.var; + inner.function(); + } + } + + private static class Inner4 { + private Inner4() {} + private int var; + private static int staticVar; + private void function() {} + private static void staticFunction() {} + } +} diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/classfiles/attributes/Synthetic/AssertFieldTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Synthetic/AssertFieldTest.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2015, 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 8044537 + * @summary Checking ACC_SYNTHETIC flag is generated for assert statement. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build AssertFieldTest SyntheticTestDriver ExpectedClass ExpectedClasses + * @run main SyntheticTestDriver AssertFieldTest + */ + +/** + * Synthetic field for assert. + */ +@ExpectedClass(className = "AssertFieldTest", + expectedMethods = {"()", "function(boolean)", "()"}, + expectedNumberOfSyntheticFields = 1) +public class AssertFieldTest { + + public void function(boolean flag) { + assert flag; + } +} diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/classfiles/attributes/Synthetic/BridgeMethodForGenericMethodTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Synthetic/BridgeMethodForGenericMethodTest.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015, 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 8044537 + * @summary Checking ACC_SYNTHETIC flag is generated for bridge method generated for generic method. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build BridgeMethodForGenericMethodTest SyntheticTestDriver ExpectedClass ExpectedClasses + * @run main SyntheticTestDriver BridgeMethodForGenericMethodTest + */ + +import java.util.ArrayList; + +/** + * Synthetic method add(Object i) for method add(Integer) + */ +@ExpectedClass(className = "BridgeMethodForGenericMethodTest", + expectedMethods = {"()", "add(java.lang.Integer)"}, + expectedNumberOfSyntheticMethods = 1) +public class BridgeMethodForGenericMethodTest extends ArrayList { + + @Override + public boolean add(Integer i) { + return true; + } +} diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/classfiles/attributes/Synthetic/BridgeMethodsForLambdaTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Synthetic/BridgeMethodsForLambdaTest.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2015, 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 8044537 + * @summary Checking ACC_SYNTHETIC flag is generated for bridge method + * generated for lambda expressions and method references. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build BridgeMethodsForLambdaTest SyntheticTestDriver ExpectedClass ExpectedClasses + * @run main SyntheticTestDriver BridgeMethodsForLambdaTest 1 + */ + +import java.util.Comparator; +import java.util.stream.IntStream; + +/** + * Synthetic members: + * 1. inner class for Inner1. + * 2. method for () -> {} in Inner1 + * 3. method for () -> {} in Inner2 + * 4. method references to private methods. + * 5. method for super::function() + * 6. method references to private static methods. + * 7. access method for private method function(). + * 8. access method for private static method staticFunction(). + * 9. method reference to vararg method. + * 10. method reference to array's method. + * 11. constructors for Inner1 and Inner2. + */ +@ExpectedClass(className = "BridgeMethodsForLambdaTest", + expectedMethods = {"()", "()", "function(java.lang.Integer[])"}, + expectedNumberOfSyntheticMethods = 6) +@ExpectedClass(className = "BridgeMethodsForLambdaTest$Inner1", + expectedMethods = {"(BridgeMethodsForLambdaTest)", "function()", "run()"}, + expectedFields = "lambda1", + expectedNumberOfSyntheticMethods = 4, + expectedNumberOfSyntheticFields = 1) +@ExpectedClass(className = "BridgeMethodsForLambdaTest$Inner2", + expectedMethods = {"()", "staticFunction()"}, + expectedFields = "lambda1", + expectedNumberOfSyntheticMethods = 3) +@ExpectedClass(className = "BridgeMethodsForLambdaTest$Inner3", + expectedMethods = {"(BridgeMethodsForLambdaTest)", "function()"}, + expectedNumberOfSyntheticMethods = 1, + expectedNumberOfSyntheticFields = 1) +@ExpectedClass(className = "BridgeMethodsForLambdaTest$Inner4", + expectedMethods = {"(BridgeMethodsForLambdaTest)", "function()"}, + expectedNumberOfSyntheticMethods = 1, + expectedNumberOfSyntheticFields = 1) +public class BridgeMethodsForLambdaTest { + + private class Inner1 implements Runnable { + private Inner1() { + } + private Runnable lambda1 = () -> { + }; + private void function() { + } + @Override + public void run() { + } + } + + private static class Inner2 { + private Runnable lambda1 = () -> { + }; + private static void staticFunction() { + } + } + + private class Inner3 { + public void function() { + } + } + + private class Inner4 extends Inner3 { + @Override + public void function() { + Runnable r = super::function; + } + } + + private static int function(Integer...vararg) { + return 0; + } + + { + Inner1 inner = new Inner1(); + Runnable l1 = inner::function; + Runnable l2 = Inner1::new; + inner.lambda1 = inner::function; + Comparator c = BridgeMethodsForLambdaTest::function; + IntStream.of(2).mapToObj(int[]::new); + } + + static { + Inner2 inner = new Inner2(); + Runnable l1 = Inner2::staticFunction; + } +} diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/classfiles/attributes/Synthetic/EnumTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Synthetic/EnumTest.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2015, 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 8044537 + * @summary Checking ACC_SYNTHETIC flag is generated for enum members. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build EnumTest SyntheticTestDriver ExpectedClass ExpectedClasses + * @run main SyntheticTestDriver EnumTest + */ + +/** + * Synthetic members: + * 1. field $VALUES. + */ +@ExpectedClass(className = "EnumTest", + expectedMethods = {"values()", "valueOf(java.lang.String)", "()", "(java.lang.String, int)"}, + expectedFields = {"A", "B"}, + expectedNumberOfSyntheticFields = 1) +public enum EnumTest { + A, B +} diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/classfiles/attributes/Synthetic/ExpectedClass.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Synthetic/ExpectedClass.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2015, 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. + */ + +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Repeatable(ExpectedClasses.class) +@Retention(RetentionPolicy.RUNTIME) +public @interface ExpectedClass { + String className(); + String[] expectedMethods() default {}; + String[] expectedFields() default {}; + int expectedNumberOfSyntheticMethods() default 0; + int expectedNumberOfSyntheticFields() default 0; +} diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/classfiles/attributes/Synthetic/ExpectedClasses.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Synthetic/ExpectedClasses.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2015, 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. + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface ExpectedClasses { + ExpectedClass[] value(); +} diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/classfiles/attributes/Synthetic/PackageInfoTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Synthetic/PackageInfoTest.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2015, 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 8044537 + * @summary Checking ACC_SYNTHETIC flag is generated for package-info. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build SyntheticTestDriver ExpectedClass ExpectedClasses + * @compile -Xpkginfo:always package_info_test/package-info.java + * @run main SyntheticTestDriver package_info_test.package-info 1 + */ + +public class PackageInfoTest { +} diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/classfiles/attributes/Synthetic/SyntheticTestDriver.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Synthetic/SyntheticTestDriver.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2015, 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. + */ + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.*; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.regex.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import com.sun.tools.classfile.*; + +/** + * The tests work as follows. Firstly, it looks through the test cases + * and extracts the appropriate compiled classes. Each test case contains + * a set of expected classes, methods and fields. Those class members must not have + * the Synthetic attribute, while other found classes, methods and fields must have + * the Synthetic attribute if they are not in the set of expected class members. + * + * Each test executes SyntheticTestDriver specifying the name of test cases and + * the number of expected synthetic classes. Each test class is annotated by + * annotations which contains non-synthetic class members. + * + * See the appropriate class for more information about a test case. + */ +public class SyntheticTestDriver extends TestResult { + + private static final String ACC_SYNTHETIC = "ACC_SYNTHETIC"; + + private final String testCaseName; + private final Map classes; + private final Map expectedClasses; + + public static void main(String[] args) + throws TestFailedException, ConstantPoolException, IOException, ClassNotFoundException { + if (args.length != 1 && args.length != 2) { + throw new IllegalArgumentException("Usage: SyntheticTestDriver []"); + } + int numberOfSyntheticClasses = args.length == 1 ? 0 : Integer.parseInt(args[1]); + new SyntheticTestDriver(args[0]).test(numberOfSyntheticClasses); + } + + public SyntheticTestDriver(String testCaseName) throws IOException, ConstantPoolException, ClassNotFoundException { + Class clazz = Class.forName(testCaseName); + this.testCaseName = testCaseName; + this.expectedClasses = Stream.of(clazz.getAnnotationsByType(ExpectedClass.class)) + .collect(Collectors.toMap(ExpectedClass::className, Function.identity())); + this.classes = new HashMap<>(); + Path classDir = getClassDir().toPath(); + Pattern filePattern = Pattern.compile(Pattern.quote(testCaseName.replace('.', File.separatorChar)) + ".*\\.class"); + List paths = Files.walk(classDir) + .map(p -> classDir.relativize(p.toAbsolutePath())) + .filter(p -> filePattern.matcher(p.toString()).matches()) + .collect(Collectors.toList()); + for (Path path : paths) { + String className = path.toString().replace(".class", "").replace(File.separatorChar, '.'); + classes.put(className, readClassFile(classDir.resolve(path).toFile())); + } + if (classes.isEmpty()) { + throw new RuntimeException("Classes have not been found."); + } + boolean success = classes.entrySet().stream() + .allMatch(e -> e.getKey().startsWith(testCaseName)); + if (!success) { + classes.forEach((className, $) -> printf("Found class: %s\n", className)); + throw new RuntimeException("Found classes are not from the test case : " + testCaseName); + } + } + + private String getMethodName(ClassFile classFile, Method method) + throws ConstantPoolException, Descriptor.InvalidDescriptor { + String methodName = method.getName(classFile.constant_pool); + String parameters = method.descriptor.getParameterTypes(classFile.constant_pool); + return methodName + parameters; + } + + public void test(int expectedNumberOfSyntheticClasses) throws TestFailedException { + try { + addTestCase(testCaseName); + Set foundClasses = new HashSet<>(); + + int numberOfSyntheticClasses = 0; + for (Map.Entry entry : classes.entrySet()) { + String className = entry.getKey(); + ClassFile classFile = entry.getValue(); + foundClasses.add(className); + if (testAttribute( + classFile, + () -> (Synthetic_attribute) classFile.getAttribute(Attribute.Synthetic), + classFile.access_flags::getClassFlags, + expectedClasses.keySet(), + className, + "Testing class " + className)) { + ++numberOfSyntheticClasses; + } + ExpectedClass expectedClass = expectedClasses.get(className); + Set expectedMethods = expectedClass != null + ? toSet(expectedClass.expectedMethods()) + : new HashSet<>(); + int numberOfSyntheticMethods = 0; + Set foundMethods = new HashSet<>(); + for (Method method : classFile.methods) { + String methodName = getMethodName(classFile, method); + foundMethods.add(methodName); + if (testAttribute( + classFile, + () -> (Synthetic_attribute) method.attributes.get(Attribute.Synthetic), + method.access_flags::getMethodFlags, + expectedMethods, + methodName, + "Testing method " + methodName + " in class " + + className)) { + ++numberOfSyntheticMethods; + } + } + checkContains(foundMethods, expectedMethods, + "Checking that all methods of class " + className + + " without Synthetic attribute have been found"); + checkEquals(numberOfSyntheticMethods, + expectedClass == null ? 0 : expectedClass.expectedNumberOfSyntheticMethods(), + "Checking number of synthetic methods in class: " + className); + + Set expectedFields = expectedClass != null + ? toSet(expectedClass.expectedFields()) + : new HashSet<>(); + int numberOfSyntheticFields = 0; + Set foundFields = new HashSet<>(); + for (Field field : classFile.fields) { + String fieldName = field.getName(classFile.constant_pool); + foundFields.add(fieldName); + if (testAttribute( + classFile, + () -> (Synthetic_attribute) field.attributes.get(Attribute.Synthetic), + field.access_flags::getFieldFlags, + expectedFields, + fieldName, + "Testing field " + fieldName + " in class " + + className)) { + ++numberOfSyntheticFields; + } + } + checkContains(foundFields, expectedFields, + "Checking that all fields of class " + className + + " without Synthetic attribute have been found"); + checkEquals(numberOfSyntheticFields, + expectedClass == null ? 0 : expectedClass.expectedNumberOfSyntheticFields(), + "Checking number of synthetic fields in class: " + className); + } + checkContains(foundClasses, expectedClasses.keySet(), + "Checking that all classes have been found"); + checkEquals(numberOfSyntheticClasses, expectedNumberOfSyntheticClasses, + "Checking number of synthetic classes"); + } catch (Exception e) { + addFailure(e); + } finally { + checkStatus(); + } + } + + private boolean testAttribute(ClassFile classFile, + Supplier getSyntheticAttribute, + Supplier> getAccessFlags, + Set expectedMembers, String memberName, + String info) throws ConstantPoolException { + echo(info); + String className = classFile.getName(); + Synthetic_attribute attr = getSyntheticAttribute.get(); + Set flags = getAccessFlags.get(); + if (expectedMembers.contains(memberName)) { + checkNull(attr, "Member must not have synthetic attribute : " + + memberName); + checkFalse(flags.contains(ACC_SYNTHETIC), + "Member must not have synthetic flag : " + memberName + + " in class : " + className); + return false; + } else { + return checkNull(attr, "Synthetic attribute should not be generated") + && checkTrue(flags.contains(ACC_SYNTHETIC), "Member must have synthetic flag : " + + memberName + " in class : " + className); + } + } + + private Set toSet(String[] strings) { + HashSet set = new HashSet<>(); + Collections.addAll(set, strings); + return set; + } +} diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/classfiles/attributes/Synthetic/ThisFieldTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Synthetic/ThisFieldTest.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015, 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 8044537 + * @summary Checking ACC_SYNTHETIC flag is generated for "this$0" field. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build ThisFieldTest SyntheticTestDriver ExpectedClass ExpectedClasses + * @run main SyntheticTestDriver ThisFieldTest + */ + +/** + * Synthetic members: + * 1. fields this$0 for local and anonymous classes. + */ +@ExpectedClass(className = "ThisFieldTest", + expectedMethods = "()") +@ExpectedClass(className = "ThisFieldTest$1Local", + expectedMethods = "(ThisFieldTest)", + expectedNumberOfSyntheticFields = 1) +@ExpectedClass(className = "ThisFieldTest$1", + expectedMethods = "(ThisFieldTest)", + expectedNumberOfSyntheticFields = 1) +public class ThisFieldTest { + { + class Local { + } + + new Local() { + }; + } +} diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/classfiles/attributes/Synthetic/package_info_test/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Synthetic/package_info_test/package-info.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2015, 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. + */ + +package package_info_test; \ No newline at end of file diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/completionDeps/DepsAndAnno.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/completionDeps/DepsAndAnno.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2015, 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 8078600 + * @summary Make sure -XDcompletionDeps does not cause an infinite loop. + * @library /tools/lib + * @build ToolBox + * @run main/othervm/timeout=10 DepsAndAnno + */ + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +public class DepsAndAnno { + + @Target(ElementType.METHOD) + @interface Test { } + + public static void main(String[] args) { + ToolBox toolBox = new ToolBox(); + toolBox.new JavacTask(ToolBox.Mode.CMDLINE) + .options("-XDcompletionDeps") + .outdir(".") + .files(ToolBox.testSrc + "/DepsAndAnno.java") + .run(); + } +} diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/diags/examples/InvalidTypeContextRepeatableAnnotation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/diags/examples/InvalidTypeContextRepeatableAnnotation.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2015, 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. + */ + +// key: compiler.err.invalid.repeatable.annotation.not.applicable.in.context + + +import java.lang.annotation.*; + +@Target({ElementType.TYPE_USE, ElementType.METHOD, ElementType.TYPE_PARAMETER}) +@Repeatable(TC.class) +@interface T { int value(); } + +@Target({ElementType.METHOD, ElementType.TYPE_PARAMETER}) +@interface TC { T[] value(); } + +public class InvalidTypeContextRepeatableAnnotation { + void method() { + this.<@T(1) @T(2) String>method2(); + } + + <@T(3) S> void method2() { + } +} diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/lambda/AvoidInfiniteReattribution.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/lambda/AvoidInfiniteReattribution.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2015, 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 8077605 + * @summary Check that when an exception occurs during Attr.visitLambda, an attempt to attribute + the lambda again is avoided rather than falling into an infinite recursion. + */ + +import java.io.IOException; +import java.net.URI; +import java.util.Arrays; +import java.util.List; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; + +import com.sun.tools.javac.api.JavacTaskImpl; +import com.sun.tools.javac.api.JavacTool; +import com.sun.tools.javac.comp.Attr; +import com.sun.tools.javac.tree.JCTree.JCVariableDecl; +import com.sun.tools.javac.util.Context; +import com.sun.tools.javac.util.Context.Factory; + +public class AvoidInfiniteReattribution { + + public static void main(String... args) throws Exception { + new AvoidInfiniteReattribution().run(); + } + + void run() throws IOException { + JavacTool tool = JavacTool.create(); + JavaSource source = new JavaSource("class Test {" + + " I i = STOP -> {};" + + " interface I {" + + " public void test(int i) {}" + + " }" + + "}"); + Context context = new Context(); + CrashingAttr.preRegister(context); + List inputs = Arrays.asList(source); + JavacTaskImpl task = + (JavacTaskImpl) tool.getTask(null, null, null, null, null, inputs, context); + try { + task.analyze(null); + throw new AssertionError("Expected exception not seen."); + } catch (StopException ex) { + //ok + } + } + + static class CrashingAttr extends Attr { + + static void preRegister(Context context) { + context.put(attrKey, (Factory) c -> new CrashingAttr(c)); + } + + CrashingAttr(Context context) { + super(context); + } + + @Override public void visitVarDef(JCVariableDecl tree) { + if (tree.name.contentEquals("STOP")) + throw new StopException(); + super.visitVarDef(tree); + } + } + + static class StopException extends NullPointerException {} + + class JavaSource extends SimpleJavaFileObject { + + String source; + + JavaSource(String source) { + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); + this.source = source; + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return source; + } + + } + +} diff -r 6a2f534a9c4b -r 1bffa0091f27 langtools/test/tools/javac/lambda/T8077605.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/lambda/T8077605.java Thu Apr 30 17:21:28 2015 -0700 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2015, 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 8077605 + * @summary Lambda with parameters in field initializer should not break compilation + * (MemberEnter.needsLazyConstValue should detect the initializer cannot be a constant) + * @compile T8077605.java + */ + +public class T8077605 { + static final String C = "" + m(str -> str); + + private static String m(I function) { + return null; + } + + interface I { + public String run(String str); + } +} +