src/share/classes/com/sun/tools/javac/comp/Attr.java

changeset 2390
b06c2db45ddb
parent 2370
acd64168cf8b
child 2391
8e7bd4c50fd1
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Mon May 12 09:53:35 2014 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue May 13 14:18:34 2014 +0100
     1.3 @@ -2143,6 +2143,11 @@
     1.4                      cdef.extending = clazz;
     1.5                  }
     1.6  
     1.7 +                if (resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK &&
     1.8 +                    isSerializable(clazztype)) {
     1.9 +                    localEnv.info.isSerializable = true;
    1.10 +                }
    1.11 +
    1.12                  attribStat(cdef, localEnv);
    1.13  
    1.14                  checkLambdaCandidate(tree, cdef.sym, clazztype);
    1.15 @@ -2298,6 +2303,9 @@
    1.16                  resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK;
    1.17          try {
    1.18              Type currentTarget = pt();
    1.19 +            if (needsRecovery && isSerializable(currentTarget)) {
    1.20 +                localEnv.info.isSerializable = true;
    1.21 +            }
    1.22              List<Type> explicitParamTypes = null;
    1.23              if (that.paramKind == JCLambda.ParameterKind.EXPLICIT) {
    1.24                  //attribute lambda parameters
    1.25 @@ -2702,17 +2710,20 @@
    1.26                  typeargtypes = attribTypes(that.typeargs, localEnv);
    1.27              }
    1.28  
    1.29 -            Type target;
    1.30              Type desc;
    1.31 -            if (pt() != Type.recoveryType) {
    1.32 -                target = targetChecker.visit(pt(), that);
    1.33 -                desc = types.findDescriptorType(target);
    1.34 +            Type currentTarget = pt();
    1.35 +            boolean isTargetSerializable =
    1.36 +                    resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK &&
    1.37 +                    isSerializable(currentTarget);
    1.38 +            if (currentTarget != Type.recoveryType) {
    1.39 +                currentTarget = targetChecker.visit(currentTarget, that);
    1.40 +                desc = types.findDescriptorType(currentTarget);
    1.41              } else {
    1.42 -                target = Type.recoveryType;
    1.43 +                currentTarget = Type.recoveryType;
    1.44                  desc = fallbackDescriptorType(that);
    1.45              }
    1.46  
    1.47 -            setFunctionalInfo(localEnv, that, pt(), desc, target, resultInfo.checkContext);
    1.48 +            setFunctionalInfo(localEnv, that, pt(), desc, currentTarget, resultInfo.checkContext);
    1.49              List<Type> argtypes = desc.getParameterTypes();
    1.50              Resolve.MethodCheck referenceCheck = rs.resolveMethodCheck;
    1.51  
    1.52 @@ -2763,10 +2774,10 @@
    1.53                  JCDiagnostic diag = diags.create(diagKind, log.currentSource(), that,
    1.54                          "invalid.mref", Kinds.kindName(that.getMode()), detailsDiag);
    1.55  
    1.56 -                if (targetError && target == Type.recoveryType) {
    1.57 +                if (targetError && currentTarget == Type.recoveryType) {
    1.58                      //a target error doesn't make sense during recovery stage
    1.59                      //as we don't know what actual parameter types are
    1.60 -                    result = that.type = target;
    1.61 +                    result = that.type = currentTarget;
    1.62                      return;
    1.63                  } else {
    1.64                      if (targetError) {
    1.65 @@ -2774,7 +2785,7 @@
    1.66                      } else {
    1.67                          log.report(diag);
    1.68                      }
    1.69 -                    result = that.type = types.createErrorType(target);
    1.70 +                    result = that.type = types.createErrorType(currentTarget);
    1.71                      return;
    1.72                  }
    1.73              }
    1.74 @@ -2785,7 +2796,7 @@
    1.75  
    1.76              if (desc.getReturnType() == Type.recoveryType) {
    1.77                  // stop here
    1.78 -                result = that.type = target;
    1.79 +                result = that.type = currentTarget;
    1.80                  return;
    1.81              }
    1.82  
    1.83 @@ -2803,7 +2814,7 @@
    1.84                      //static ref with class type-args
    1.85                      log.error(that.expr.pos(), "invalid.mref", Kinds.kindName(that.getMode()),
    1.86                              diags.fragment("static.mref.with.targs"));
    1.87 -                    result = that.type = types.createErrorType(target);
    1.88 +                    result = that.type = types.createErrorType(currentTarget);
    1.89                      return;
    1.90                  }
    1.91  
    1.92 @@ -2812,7 +2823,7 @@
    1.93                      //no static bound mrefs
    1.94                      log.error(that.expr.pos(), "invalid.mref", Kinds.kindName(that.getMode()),
    1.95                              diags.fragment("static.bound.mref"));
    1.96 -                    result = that.type = types.createErrorType(target);
    1.97 +                    result = that.type = types.createErrorType(currentTarget);
    1.98                      return;
    1.99                  }
   1.100  
   1.101 @@ -2820,6 +2831,10 @@
   1.102                      // Check that super-qualified symbols are not abstract (JLS)
   1.103                      rs.checkNonAbstract(that.pos(), that.sym);
   1.104                  }
   1.105 +
   1.106 +                if (isTargetSerializable) {
   1.107 +                    chk.checkElemAccessFromSerializableLambda(that);
   1.108 +                }
   1.109              }
   1.110  
   1.111              ResultInfo checkInfo =
   1.112 @@ -2851,9 +2866,9 @@
   1.113                      resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE;
   1.114              checkReferenceCompatible(that, desc, refType, resultInfo.checkContext, isSpeculativeRound);
   1.115              if (!isSpeculativeRound) {
   1.116 -                checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), desc, target);
   1.117 +                checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), desc, currentTarget);
   1.118              }
   1.119 -            result = check(that, target, VAL, resultInfo);
   1.120 +            result = check(that, currentTarget, VAL, resultInfo);
   1.121          } catch (Types.FunctionDescriptorLookupError ex) {
   1.122              JCDiagnostic cause = ex.getDiagnostic();
   1.123              resultInfo.checkContext.report(that, cause);
   1.124 @@ -3193,6 +3208,11 @@
   1.125              while (env1.outer != null && !rs.isAccessible(env, env1.enclClass.sym.type, sym))
   1.126                  env1 = env1.outer;
   1.127          }
   1.128 +
   1.129 +        if (env.info.isSerializable) {
   1.130 +            chk.checkElemAccessFromSerializableLambda(tree);
   1.131 +        }
   1.132 +
   1.133          result = checkId(tree, env1.enclClass.sym.type, sym, env, resultInfo);
   1.134      }
   1.135  
   1.136 @@ -3317,6 +3337,10 @@
   1.137              }
   1.138          }
   1.139  
   1.140 +        if (env.info.isSerializable) {
   1.141 +            chk.checkElemAccessFromSerializableLambda(tree);
   1.142 +        }
   1.143 +
   1.144          env.info.selectSuper = selectSuperPrev;
   1.145          result = checkId(tree, site, sym, env, resultInfo);
   1.146      }
   1.147 @@ -4195,6 +4219,11 @@
   1.148                      ((c.flags_field & (Flags.ENUM | Flags.COMPOUND)) == 0)) {
   1.149                      log.error(env.tree.pos(), "enum.types.not.extensible");
   1.150                  }
   1.151 +
   1.152 +                if (isSerializable(c.type)) {
   1.153 +                    env.info.isSerializable = true;
   1.154 +                }
   1.155 +
   1.156                  attribClassBody(env, c);
   1.157  
   1.158                  chk.checkDeprecatedAnnotation(env.tree.pos(), c);
   1.159 @@ -4308,7 +4337,7 @@
   1.160  
   1.161          // Check for proper use of serialVersionUID
   1.162          if (env.info.lint.isEnabled(LintCategory.SERIAL) &&
   1.163 -            isSerializable(c) &&
   1.164 +            isSerializable(c.type) &&
   1.165              (c.flags() & Flags.ENUM) == 0 &&
   1.166              checkForSerial(c)) {
   1.167              checkSerialVersionUID(tree, c);
   1.168 @@ -4348,15 +4377,15 @@
   1.169              return null;
   1.170          }
   1.171  
   1.172 -        /** check if a class is a subtype of Serializable, if that is available. */
   1.173 -        private boolean isSerializable(ClassSymbol c) {
   1.174 +        /** check if a type is a subtype of Serializable, if that is available. */
   1.175 +        boolean isSerializable(Type t) {
   1.176              try {
   1.177                  syms.serializableType.complete();
   1.178              }
   1.179              catch (CompletionFailure e) {
   1.180                  return false;
   1.181              }
   1.182 -            return types.isSubtype(c.type, syms.serializableType);
   1.183 +            return types.isSubtype(t, syms.serializableType);
   1.184          }
   1.185  
   1.186          /** Check that an appropriate serialVersionUID member is defined. */

mercurial