# HG changeset patch # User asaha # Date 1452903873 28800 # Node ID 8969d6096fe123922bb3ac0c8f6f7b18c1c7668e # Parent 6b38b7b0ed87ad1c68b91dd6ba58741562752e1c# Parent 9731ab1f18eeccd4678d707d9b1ee49eb9729e42 Merge diff -r 6b38b7b0ed87 -r 8969d6096fe1 src/share/classes/com/sun/tools/doclets/internal/toolkit/util/VisibleMemberMap.java --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/VisibleMemberMap.java Tue Jan 05 08:53:02 2016 -0800 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/VisibleMemberMap.java Fri Jan 15 16:24:33 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2016, 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 @@ -250,7 +250,7 @@ for (int i = 0; i < list.size(); i++) { Object key = getMemberKey(list.get(i)); Map memberLevelMap = memberNameMap.get(key); - if (level.equals(memberLevelMap.get(list.get(i)))) + if (memberLevelMap != null && level.equals(memberLevelMap.get(list.get(i)))) memberLevelMap.remove(list.get(i)); } } diff -r 6b38b7b0ed87 -r 8969d6096fe1 src/share/classes/com/sun/tools/javac/comp/AttrContext.java --- a/src/share/classes/com/sun/tools/javac/comp/AttrContext.java Tue Jan 05 08:53:02 2016 -0800 +++ b/src/share/classes/com/sun/tools/javac/comp/AttrContext.java Fri Jan 15 16:24:33 2016 -0800 @@ -25,6 +25,7 @@ package com.sun.tools.javac.comp; +import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.util.*; import com.sun.tools.javac.code.*; @@ -80,6 +81,13 @@ */ Type defaultSuperCallSite = null; + /** Tree that when non null, is to be preferentially used in diagnostics. + * Usually Env.tree is the tree to be referred to in messages, + * but this may not be true during the window a method is looked up in enclosing + * contexts (JDK-8145466) + */ + JCTree preferredTreeForDiagnostics; + /** Duplicate this context, replacing scope field and copying all others. */ AttrContext dup(Scope scope) { @@ -94,6 +102,7 @@ info.returnResult = returnResult; info.defaultSuperCallSite = defaultSuperCallSite; info.isSerializable = isSerializable; + info.preferredTreeForDiagnostics = preferredTreeForDiagnostics; return info; } diff -r 6b38b7b0ed87 -r 8969d6096fe1 src/share/classes/com/sun/tools/javac/comp/Resolve.java --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Tue Jan 05 08:53:02 2016 -0800 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Fri Jan 15 16:24:33 2016 -0800 @@ -717,7 +717,8 @@ Warner warn) { //should we expand formals? boolean useVarargs = deferredAttrContext.phase.isVarargsRequired(); - List trees = TreeInfo.args(env.tree); + JCTree callTree = treeForDiagnostics(env); + List trees = TreeInfo.args(callTree); //inference context used during this method check InferenceContext inferenceContext = deferredAttrContext.inferenceContext; @@ -726,7 +727,7 @@ if (varargsFormal == null && argtypes.size() != formals.size()) { - reportMC(env.tree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args + reportMC(callTree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args } while (argtypes.nonEmpty() && formals.head != varargsFormal) { @@ -738,7 +739,7 @@ } if (formals.head != varargsFormal) { - reportMC(env.tree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args + reportMC(callTree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args } if (useVarargs) { @@ -754,6 +755,11 @@ } } + // where + private JCTree treeForDiagnostics(Env env) { + return env.info.preferredTreeForDiagnostics != null ? env.info.preferredTreeForDiagnostics : env.tree; + } + /** * Does the actual argument conforms to the corresponding formal? */ @@ -1828,17 +1834,23 @@ boolean staticOnly = false; while (env1.outer != null) { if (isStatic(env1)) staticOnly = true; - sym = findMethod( - env1, env1.enclClass.sym.type, name, argtypes, typeargtypes, - allowBoxing, useVarargs, false); - if (sym.exists()) { - if (staticOnly && - sym.kind == MTH && - sym.owner.kind == TYP && - (sym.flags() & STATIC) == 0) return new StaticError(sym); - else return sym; - } else if (sym.kind < bestSoFar.kind) { - bestSoFar = sym; + Assert.check(env1.info.preferredTreeForDiagnostics == null); + env1.info.preferredTreeForDiagnostics = env.tree; + try { + sym = findMethod( + env1, env1.enclClass.sym.type, name, argtypes, typeargtypes, + allowBoxing, useVarargs, false); + if (sym.exists()) { + if (staticOnly && + sym.kind == MTH && + sym.owner.kind == TYP && + (sym.flags() & STATIC) == 0) return new StaticError(sym); + else return sym; + } else if (sym.kind < bestSoFar.kind) { + bestSoFar = sym; + } + } finally { + env1.info.preferredTreeForDiagnostics = null; } if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true; env1 = env1.outer; @@ -4214,7 +4226,11 @@ DiagnosticPosition preferedPos, DiagnosticSource preferredSource, DiagnosticType preferredKind, JCDiagnostic d) { JCDiagnostic cause = (JCDiagnostic)d.getArgs()[0]; - return diags.create(preferredKind, preferredSource, d.getDiagnosticPosition(), + DiagnosticPosition pos = d.getDiagnosticPosition(); + if (pos == null) { + pos = preferedPos; + } + return diags.create(preferredKind, preferredSource, pos, "prob.found.req", cause); } }); diff -r 6b38b7b0ed87 -r 8969d6096fe1 test/tools/javac/diags/DiagnosticRewriterTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/diags/DiagnosticRewriterTest.java Fri Jan 15 16:24:33 2016 -0800 @@ -0,0 +1,18 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8145466 8146533 + * @summary javac: No line numbers in compilation error + * @compile/fail/ref=DiagnosticRewriterTest.out -Xdiags:compact -XDrawDiagnostics DiagnosticRewriterTest.java + */ + +class DiagnosticRewriterTest { + void test() { + new Object() { + void g() { + m(2L); + } + }; + } + + void m(int i) { } +} diff -r 6b38b7b0ed87 -r 8969d6096fe1 test/tools/javac/diags/DiagnosticRewriterTest.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/diags/DiagnosticRewriterTest.out Fri Jan 15 16:24:33 2016 -0800 @@ -0,0 +1,3 @@ +DiagnosticRewriterTest.java:12:15: compiler.err.prob.found.req: (compiler.misc.possible.loss.of.precision: long, int) +- compiler.note.compressed.diags +1 error diff -r 6b38b7b0ed87 -r 8969d6096fe1 test/tools/javac/diags/DiagnosticRewriterTest2.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/diags/DiagnosticRewriterTest2.java Fri Jan 15 16:24:33 2016 -0800 @@ -0,0 +1,22 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8145466 8146533 + * @summary javac: No line numbers in compilation error + * @compile/fail/ref=DiagnosticRewriterTest2.out -Xdiags:compact -XDrawDiagnostics DiagnosticRewriterTest2.java + */ + +class DiagnosticRewriterTest2 { + class Bar { + Bar(Object o) { } + } + void test() { + new Bar(null) { + void g() { + m(2L); + m(); + } + }; + } + + void m(int i) { } +} diff -r 6b38b7b0ed87 -r 8969d6096fe1 test/tools/javac/diags/DiagnosticRewriterTest2.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/diags/DiagnosticRewriterTest2.out Fri Jan 15 16:24:33 2016 -0800 @@ -0,0 +1,4 @@ +DiagnosticRewriterTest2.java:15:15: compiler.err.prob.found.req: (compiler.misc.possible.loss.of.precision: long, int) +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) +- compiler.note.compressed.diags +2 errors