# HG changeset patch # User sadayapalam # Date 1464267125 -19800 # Node ID eb4a0b7e67a112129f710464c6c165578a3c1047 # Parent 6b708cd902415a0edba2aa639debacd9870ebefc 8154052: Java compiler error displays line from the wrong file Summary: Compiler should update the diagnostic source properly. Reviewed-by: mcimadamore diff -r 6b708cd90241 -r eb4a0b7e67a1 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 Wed May 25 22:32:16 2016 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java Thu May 26 18:22:05 2016 +0530 @@ -811,6 +811,7 @@ DiagnosticPosition prevLintPos = deferredLintHandler.setPos(variable.pos()); + final JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile); try { Type itype = attribExpr(variable.init, env, type); if (itype.constValue() != null) { @@ -819,6 +820,7 @@ return null; } } finally { + log.useSource(prevSource); deferredLintHandler.setPos(prevLintPos); } } diff -r 6b708cd90241 -r eb4a0b7e67a1 langtools/test/tools/javac/diags/EagerInitCheck.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/diags/EagerInitCheck.java Thu May 26 18:22:05 2016 +0530 @@ -0,0 +1,33 @@ +/* + * Copyright (c) 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 + * 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 8154052 + * @summary Java compiler error displays line from the wrong file + * @compile/fail/ref=EagerInitCheck.out -XDrawDiagnostics EagerInitCheck.java + */ + +public class EagerInitCheck implements IEagerInitCheck { + float x = VAL; +} \ No newline at end of file diff -r 6b708cd90241 -r eb4a0b7e67a1 langtools/test/tools/javac/diags/EagerInitCheck.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/diags/EagerInitCheck.out Thu May 26 18:22:05 2016 +0530 @@ -0,0 +1,2 @@ +IEagerInitCheck.java:25:17: compiler.err.prob.found.req: (compiler.misc.possible.loss.of.precision: double, float) +1 error \ No newline at end of file diff -r 6b708cd90241 -r eb4a0b7e67a1 langtools/test/tools/javac/diags/IEagerInitCheck.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/diags/IEagerInitCheck.java Thu May 26 18:22:05 2016 +0530 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 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 + * 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. + */ + +public interface IEagerInitCheck { + float VAL = 1.0; +} \ No newline at end of file