Fri, 15 Jan 2016 16:24:33 -0800
Merge
1.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/VisibleMemberMap.java Tue Jan 05 08:53:02 2016 -0800 1.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/VisibleMemberMap.java Fri Jan 15 16:24:33 2016 -0800 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -250,7 +250,7 @@ 1.11 for (int i = 0; i < list.size(); i++) { 1.12 Object key = getMemberKey(list.get(i)); 1.13 Map<ProgramElementDoc, String> memberLevelMap = memberNameMap.get(key); 1.14 - if (level.equals(memberLevelMap.get(list.get(i)))) 1.15 + if (memberLevelMap != null && level.equals(memberLevelMap.get(list.get(i)))) 1.16 memberLevelMap.remove(list.get(i)); 1.17 } 1.18 }
2.1 --- a/src/share/classes/com/sun/tools/javac/comp/AttrContext.java Tue Jan 05 08:53:02 2016 -0800 2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/AttrContext.java Fri Jan 15 16:24:33 2016 -0800 2.3 @@ -25,6 +25,7 @@ 2.4 2.5 package com.sun.tools.javac.comp; 2.6 2.7 +import com.sun.tools.javac.tree.JCTree; 2.8 import com.sun.tools.javac.util.*; 2.9 import com.sun.tools.javac.code.*; 2.10 2.11 @@ -80,6 +81,13 @@ 2.12 */ 2.13 Type defaultSuperCallSite = null; 2.14 2.15 + /** Tree that when non null, is to be preferentially used in diagnostics. 2.16 + * Usually Env<AttrContext>.tree is the tree to be referred to in messages, 2.17 + * but this may not be true during the window a method is looked up in enclosing 2.18 + * contexts (JDK-8145466) 2.19 + */ 2.20 + JCTree preferredTreeForDiagnostics; 2.21 + 2.22 /** Duplicate this context, replacing scope field and copying all others. 2.23 */ 2.24 AttrContext dup(Scope scope) { 2.25 @@ -94,6 +102,7 @@ 2.26 info.returnResult = returnResult; 2.27 info.defaultSuperCallSite = defaultSuperCallSite; 2.28 info.isSerializable = isSerializable; 2.29 + info.preferredTreeForDiagnostics = preferredTreeForDiagnostics; 2.30 return info; 2.31 } 2.32
3.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Tue Jan 05 08:53:02 2016 -0800 3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Fri Jan 15 16:24:33 2016 -0800 3.3 @@ -717,7 +717,8 @@ 3.4 Warner warn) { 3.5 //should we expand formals? 3.6 boolean useVarargs = deferredAttrContext.phase.isVarargsRequired(); 3.7 - List<JCExpression> trees = TreeInfo.args(env.tree); 3.8 + JCTree callTree = treeForDiagnostics(env); 3.9 + List<JCExpression> trees = TreeInfo.args(callTree); 3.10 3.11 //inference context used during this method check 3.12 InferenceContext inferenceContext = deferredAttrContext.inferenceContext; 3.13 @@ -726,7 +727,7 @@ 3.14 3.15 if (varargsFormal == null && 3.16 argtypes.size() != formals.size()) { 3.17 - reportMC(env.tree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args 3.18 + reportMC(callTree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args 3.19 } 3.20 3.21 while (argtypes.nonEmpty() && formals.head != varargsFormal) { 3.22 @@ -738,7 +739,7 @@ 3.23 } 3.24 3.25 if (formals.head != varargsFormal) { 3.26 - reportMC(env.tree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args 3.27 + reportMC(callTree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args 3.28 } 3.29 3.30 if (useVarargs) { 3.31 @@ -754,6 +755,11 @@ 3.32 } 3.33 } 3.34 3.35 + // where 3.36 + private JCTree treeForDiagnostics(Env<AttrContext> env) { 3.37 + return env.info.preferredTreeForDiagnostics != null ? env.info.preferredTreeForDiagnostics : env.tree; 3.38 + } 3.39 + 3.40 /** 3.41 * Does the actual argument conforms to the corresponding formal? 3.42 */ 3.43 @@ -1828,17 +1834,23 @@ 3.44 boolean staticOnly = false; 3.45 while (env1.outer != null) { 3.46 if (isStatic(env1)) staticOnly = true; 3.47 - sym = findMethod( 3.48 - env1, env1.enclClass.sym.type, name, argtypes, typeargtypes, 3.49 - allowBoxing, useVarargs, false); 3.50 - if (sym.exists()) { 3.51 - if (staticOnly && 3.52 - sym.kind == MTH && 3.53 - sym.owner.kind == TYP && 3.54 - (sym.flags() & STATIC) == 0) return new StaticError(sym); 3.55 - else return sym; 3.56 - } else if (sym.kind < bestSoFar.kind) { 3.57 - bestSoFar = sym; 3.58 + Assert.check(env1.info.preferredTreeForDiagnostics == null); 3.59 + env1.info.preferredTreeForDiagnostics = env.tree; 3.60 + try { 3.61 + sym = findMethod( 3.62 + env1, env1.enclClass.sym.type, name, argtypes, typeargtypes, 3.63 + allowBoxing, useVarargs, false); 3.64 + if (sym.exists()) { 3.65 + if (staticOnly && 3.66 + sym.kind == MTH && 3.67 + sym.owner.kind == TYP && 3.68 + (sym.flags() & STATIC) == 0) return new StaticError(sym); 3.69 + else return sym; 3.70 + } else if (sym.kind < bestSoFar.kind) { 3.71 + bestSoFar = sym; 3.72 + } 3.73 + } finally { 3.74 + env1.info.preferredTreeForDiagnostics = null; 3.75 } 3.76 if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true; 3.77 env1 = env1.outer; 3.78 @@ -4214,7 +4226,11 @@ 3.79 DiagnosticPosition preferedPos, DiagnosticSource preferredSource, 3.80 DiagnosticType preferredKind, JCDiagnostic d) { 3.81 JCDiagnostic cause = (JCDiagnostic)d.getArgs()[0]; 3.82 - return diags.create(preferredKind, preferredSource, d.getDiagnosticPosition(), 3.83 + DiagnosticPosition pos = d.getDiagnosticPosition(); 3.84 + if (pos == null) { 3.85 + pos = preferedPos; 3.86 + } 3.87 + return diags.create(preferredKind, preferredSource, pos, 3.88 "prob.found.req", cause); 3.89 } 3.90 });
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/tools/javac/diags/DiagnosticRewriterTest.java Fri Jan 15 16:24:33 2016 -0800 4.3 @@ -0,0 +1,18 @@ 4.4 +/* 4.5 + * @test /nodynamiccopyright/ 4.6 + * @bug 8145466 8146533 4.7 + * @summary javac: No line numbers in compilation error 4.8 + * @compile/fail/ref=DiagnosticRewriterTest.out -Xdiags:compact -XDrawDiagnostics DiagnosticRewriterTest.java 4.9 + */ 4.10 + 4.11 +class DiagnosticRewriterTest { 4.12 + void test() { 4.13 + new Object() { 4.14 + void g() { 4.15 + m(2L); 4.16 + } 4.17 + }; 4.18 + } 4.19 + 4.20 + void m(int i) { } 4.21 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/tools/javac/diags/DiagnosticRewriterTest.out Fri Jan 15 16:24:33 2016 -0800 5.3 @@ -0,0 +1,3 @@ 5.4 +DiagnosticRewriterTest.java:12:15: compiler.err.prob.found.req: (compiler.misc.possible.loss.of.precision: long, int) 5.5 +- compiler.note.compressed.diags 5.6 +1 error
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/test/tools/javac/diags/DiagnosticRewriterTest2.java Fri Jan 15 16:24:33 2016 -0800 6.3 @@ -0,0 +1,22 @@ 6.4 +/* 6.5 + * @test /nodynamiccopyright/ 6.6 + * @bug 8145466 8146533 6.7 + * @summary javac: No line numbers in compilation error 6.8 + * @compile/fail/ref=DiagnosticRewriterTest2.out -Xdiags:compact -XDrawDiagnostics DiagnosticRewriterTest2.java 6.9 + */ 6.10 + 6.11 +class DiagnosticRewriterTest2 { 6.12 + class Bar { 6.13 + Bar(Object o) { } 6.14 + } 6.15 + void test() { 6.16 + new Bar(null) { 6.17 + void g() { 6.18 + m(2L); 6.19 + m(); 6.20 + } 6.21 + }; 6.22 + } 6.23 + 6.24 + void m(int i) { } 6.25 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/test/tools/javac/diags/DiagnosticRewriterTest2.out Fri Jan 15 16:24:33 2016 -0800 7.3 @@ -0,0 +1,4 @@ 7.4 +DiagnosticRewriterTest2.java:15:15: compiler.err.prob.found.req: (compiler.misc.possible.loss.of.precision: long, int) 7.5 +DiagnosticRewriterTest2.java:16:13: compiler.err.cant.apply.symbol: kindname.method, m, int, compiler.misc.no.args, kindname.class, DiagnosticRewriterTest2, (compiler.misc.arg.length.mismatch) 7.6 +- compiler.note.compressed.diags 7.7 +2 errors