langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java
changeset 18657 2bd14bebdf57
parent 18644 02f65c63159c
child 18662 1cac45e71eb9
equal deleted inserted replaced
18656:d66c77f01912 18657:2bd14bebdf57
   754      */
   754      */
   755     public Object attribLazyConstantValue(Env<AttrContext> env,
   755     public Object attribLazyConstantValue(Env<AttrContext> env,
   756                                       JCTree.JCExpression initializer,
   756                                       JCTree.JCExpression initializer,
   757                                       Type type) {
   757                                       Type type) {
   758 
   758 
   759         // in case no lint value has been set up for this env, scan up
   759         /*  When this env was created, it didn't have the correct lint nor had
   760         // env stack looking for smallest enclosing env for which it is set.
   760          *  annotations has been processed.
   761         Env<AttrContext> lintEnv = env;
   761          *  But now at this phase we have already processed annotations and the
   762         while (lintEnv.info.lint == null)
   762          *  correct lint must have been set in chk, so we should use that one to
   763             lintEnv = lintEnv.next;
   763          *  attribute the initializer.
   764 
   764          */
   765         // Having found the enclosing lint value, we can initialize the lint value for this class
   765         Lint prevLint = env.info.lint;
   766         // ... but ...
   766         env.info.lint = chk.getLint();
   767         // There's a problem with evaluating annotations in the right order, such that
   767 
   768         // env.info.enclVar.attributes_field might not yet have been evaluated, and so might be
       
   769         // null. In that case, calling augment will throw an NPE. To avoid this, for now we
       
   770         // revert to the jdk 6 behavior and ignore the (unevaluated) attributes.
       
   771         if (env.info.enclVar.annotationsPendingCompletion()) {
       
   772             env.info.lint = lintEnv.info.lint;
       
   773         } else {
       
   774             env.info.lint = lintEnv.info.lint.augment(env.info.enclVar);
       
   775         }
       
   776 
       
   777         Lint prevLint = chk.setLint(env.info.lint);
       
   778         JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile);
   768         JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile);
   779 
   769 
   780         try {
   770         try {
   781             // Use null as symbol to not attach the type annotation to any symbol.
   771             // Use null as symbol to not attach the type annotation to any symbol.
   782             // The initializer will later also be visited and then we'll attach
   772             // The initializer will later also be visited and then we'll attach
   784             // This prevents having multiple type annotations, just because of
   774             // This prevents having multiple type annotations, just because of
   785             // lazy constant value evaluation.
   775             // lazy constant value evaluation.
   786             memberEnter.typeAnnotate(initializer, env, null);
   776             memberEnter.typeAnnotate(initializer, env, null);
   787             annotate.flush();
   777             annotate.flush();
   788             Type itype = attribExpr(initializer, env, type);
   778             Type itype = attribExpr(initializer, env, type);
   789             if (itype.constValue() != null)
   779             if (itype.constValue() != null) {
   790                 return coerce(itype, type).constValue();
   780                 return coerce(itype, type).constValue();
   791             else
   781             } else {
   792                 return null;
   782                 return null;
       
   783             }
   793         } finally {
   784         } finally {
   794             env.info.lint = prevLint;
   785             env.info.lint = prevLint;
   795             log.useSource(prevSource);
   786             log.useSource(prevSource);
   796         }
   787         }
   797     }
   788     }