Skip to content
Permalink
Browse files
8259359: javac does not attribute unexpected super constructor invoca…
…tion qualifier, and may crash

Reviewed-by: vromero
  • Loading branch information
lgxbslgx authored and Vicente Romero committed Jan 27, 2021
1 parent 684c855 commit 0eed2c3312fbb5e06bb9c41b4d210790bd1822a4
Showing 2 changed files with 103 additions and 0 deletions.
@@ -2404,6 +2404,7 @@ public void visitApply(JCMethodInvocation tree) {
} else if (tree.meth.hasTag(SELECT)) {
log.error(tree.meth.pos(),
Errors.IllegalQualNotIcls(site.tsym));
attribExpr(((JCFieldAccess) tree.meth).selected, localEnv, site);
}

// if we're calling a java.lang.Enum constructor,
@@ -2429,6 +2430,8 @@ public void visitApply(JCMethodInvocation tree) {
Type mpt = newMethodTemplate(resultInfo.pt, argtypes, typeargtypes);
checkId(tree.meth, site, sym, localEnv,
new ResultInfo(kind, mpt));
} else if (site.hasTag(ERROR) && tree.meth.hasTag(SELECT)) {
attribExpr(((JCFieldAccess) tree.meth).selected, localEnv, site);
}
// Otherwise, `site' is an error type and we do nothing
result = tree.type = syms.voidType;
@@ -0,0 +1,100 @@
/*
* Copyright (c) 2021, 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 8259359
* @summary javac does not attribute unexpected super constructor invocation qualifier, and may crash
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.main
* jdk.compiler/com.sun.tools.javac.api
* @build toolbox.ToolBox toolbox.JavacTask
* @run main T8259359
*/

import java.util.List;
import java.util.Arrays;

import toolbox.ToolBox;
import toolbox.TestRunner;
import toolbox.JavacTask;
import toolbox.Task;

public class T8259359 extends TestRunner {
ToolBox tb;

public T8259359() {
super(System.err);
tb = new ToolBox();
}

public static void main(String[] args) throws Exception {
new T8259359().runTests();
}

@Test
public void testSuperConstructorCallInErrorClass() throws Exception {
String code = """
public class SuperConstructorCallInErrorClass extends Undefined1 {
public SuperConstructorCallInErrorClass(int i) {
new Undefined2() { public void test(int i) { Undefined3 u; } }.super();
}
}""";
List<String> output = new JavacTask(tb)
.sources(code)
.options("-XDshould-stop.at=FLOW", "-XDdev", "-XDrawDiagnostics")
.run(Task.Expect.FAIL)
.writeAll()
.getOutputLines(Task.OutputKind.DIRECT);
List<String> expected = Arrays.asList(
"SuperConstructorCallInErrorClass.java:1:55: compiler.err.cant.resolve: kindname.class, Undefined1, , ",
"SuperConstructorCallInErrorClass.java:3:14: compiler.err.cant.resolve.location: kindname.class, " +
"Undefined2, , , (compiler.misc.location: kindname.class, SuperConstructorCallInErrorClass, null)",
"SuperConstructorCallInErrorClass.java:3:55: compiler.err.cant.resolve: kindname.class, Undefined3, , ",
"3 errors");
tb.checkEqual(expected, output);
}

@Test
public void testSuperConstructorCallInNormalClass() throws Exception {
String code = """
public class SuperConstructorCallInNormalClass {
public SuperConstructorCallInNormalClass(int i) {
new Undefined2() { public void test(int i) { Undefined3 u; } }.super();
}
}""";
List<String> output = new JavacTask(tb)
.sources(code)
.options("-XDshould-stop.at=FLOW", "-XDdev", "-XDrawDiagnostics")
.run(Task.Expect.FAIL)
.writeAll()
.getOutputLines(Task.OutputKind.DIRECT);
List<String> expected = Arrays.asList(
"SuperConstructorCallInNormalClass.java:3:72: compiler.err.illegal.qual.not.icls: java.lang.Object",
"SuperConstructorCallInNormalClass.java:3:14: compiler.err.cant.resolve.location: kindname.class, " +
"Undefined2, , , (compiler.misc.location: kindname.class, SuperConstructorCallInNormalClass, null)",
"SuperConstructorCallInNormalClass.java:3:55: compiler.err.cant.resolve: kindname.class, Undefined3, , ",
"3 errors");
tb.checkEqual(expected, output);
}
}

1 comment on commit 0eed2c3

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 0eed2c3 Jan 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.