mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-31 13:38:47 +00:00
8079470: Misleading error message when explicit signature constructor is called with wrong arguments
Reviewed-by: jlaskey, hannesw
This commit is contained in:
parent
a2301acb62
commit
b9fbd2d32d
@ -86,6 +86,9 @@ final class NashornBottomLinker implements GuardingDynamicLinker, GuardingTypeCo
|
||||
final String operator = desc.getFirstOperator();
|
||||
switch (operator) {
|
||||
case "new":
|
||||
if(BeansLinker.isDynamicConstructor(self)) {
|
||||
throw typeError("no.constructor.matches.args", ScriptRuntime.safeToString(self));
|
||||
}
|
||||
if(BeansLinker.isDynamicMethod(self)) {
|
||||
throw typeError("method.not.constructor", ScriptRuntime.safeToString(self));
|
||||
}
|
||||
|
||||
@ -144,6 +144,7 @@ type.error.extend.ERROR_FINAL_FINALIZER=Can not extend class because {0} has a f
|
||||
type.error.extend.ERROR_OTHER=Can not extend/implement {0} because of {1}
|
||||
type.error.no.constructor.matches.args=Can not construct {0} with the passed arguments; they do not match any of its constructor signatures.
|
||||
type.error.no.method.matches.args=Can not invoke method {0} with the passed arguments; they do not match any of its method signatures.
|
||||
type.error.no.constructor.matches.args=Can not create new object with constructor {0} with the passed arguments; they do not match any of its method signatures.
|
||||
type.error.method.not.constructor=Java method {0} cannot be used as a constructor.
|
||||
type.error.env.not.object=$ENV must be an Object.
|
||||
type.error.unsupported.java.to.type=Unsupported Java.to target type {0}.
|
||||
|
||||
44
nashorn/test/script/basic/JDK-8079470.js
Normal file
44
nashorn/test/script/basic/JDK-8079470.js
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2015 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* JDK-8079470: Misleading error message when explicit signature constructor is called with wrong arguments
|
||||
*
|
||||
* @test
|
||||
* @run
|
||||
*/
|
||||
|
||||
|
||||
var File = Java.type("java.io.File");
|
||||
try {
|
||||
var f = new File['(String,String)']();
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
|
||||
var Color = java.awt["Color(int,int,int)"]
|
||||
try {
|
||||
var c = new Color(255, 255)
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
2
nashorn/test/script/basic/JDK-8079470.js.EXPECTED
Normal file
2
nashorn/test/script/basic/JDK-8079470.js.EXPECTED
Normal file
@ -0,0 +1,2 @@
|
||||
TypeError: Can not create new object with constructor [jdk.internal.dynalink.beans.SimpleDynamicMethod File java.io.File.java.io.File(String,String)] with the passed arguments; they do not match any of its method signatures.
|
||||
TypeError: Can not create new object with constructor [jdk.internal.dynalink.beans.SimpleDynamicMethod Color java.awt.Color.java.awt.Color(int,int,int)] with the passed arguments; they do not match any of its method signatures.
|
||||
Loading…
x
Reference in New Issue
Block a user