mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-15 18:33:41 +00:00
8068580: make JavaAdapterFactory.isAutoConvertibleFromFunction more robust
Reviewed-by: lagergren, sundar
This commit is contained in:
parent
dc2d8b7e11
commit
faf445e144
@ -48,28 +48,25 @@ final class AdaptationResult {
|
||||
ERROR_NO_ACCESSIBLE_CONSTRUCTOR,
|
||||
ERROR_MULTIPLE_SUPERCLASSES,
|
||||
ERROR_NO_COMMON_LOADER,
|
||||
ERROR_FINAL_FINALIZER
|
||||
ERROR_FINAL_FINALIZER,
|
||||
ERROR_OTHER
|
||||
}
|
||||
|
||||
static final AdaptationResult SUCCESSFUL_RESULT = new AdaptationResult(Outcome.SUCCESS, "");
|
||||
|
||||
private final Outcome outcome;
|
||||
private final String classList;
|
||||
private final String[] messageArgs;
|
||||
|
||||
AdaptationResult(final Outcome outcome, final String classList) {
|
||||
AdaptationResult(final Outcome outcome, final String... messageArgs) {
|
||||
this.outcome = outcome;
|
||||
this.classList = classList;
|
||||
this.messageArgs = messageArgs;
|
||||
}
|
||||
|
||||
Outcome getOutcome() {
|
||||
return outcome;
|
||||
}
|
||||
|
||||
String getClassList() {
|
||||
return classList;
|
||||
}
|
||||
|
||||
ECMAException typeError() {
|
||||
return ECMAErrors.typeError("extend." + outcome, classList);
|
||||
return ECMAErrors.typeError("extend." + outcome, messageArgs);
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,7 +184,7 @@ public final class JavaAdapterFactory {
|
||||
final ClassAndLoader definingClassAndLoader = ClassAndLoader.getDefiningClassAndLoader(types);
|
||||
|
||||
final Map<List<Class<?>>, AdapterInfo> adapterInfoMap = ADAPTER_INFO_MAPS.get(definingClassAndLoader.getRepresentativeClass());
|
||||
final List<Class<?>> typeList = types.length == 1 ? getSingletonClassList(types[0]) : Arrays.asList(types.clone());
|
||||
final List<Class<?>> typeList = types.length == 1 ? Collections.<Class<?>>singletonList(types[0]) : Arrays.asList(types.clone());
|
||||
AdapterInfo adapterInfo;
|
||||
synchronized(adapterInfoMap) {
|
||||
adapterInfo = adapterInfoMap.get(typeList);
|
||||
@ -196,11 +196,6 @@ public final class JavaAdapterFactory {
|
||||
return adapterInfo;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private static List<Class<?>> getSingletonClassList(final Class<?> clazz) {
|
||||
return (List)Collections.singletonList(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given class, create its adapter class and associated info.
|
||||
* @param type the class for which the adapter is created
|
||||
@ -241,6 +236,8 @@ public final class JavaAdapterFactory {
|
||||
return new AdapterInfo(effectiveSuperClass, interfaces, definingClassAndLoader);
|
||||
} catch (final AdaptationException e) {
|
||||
return new AdapterInfo(e.getAdaptationResult());
|
||||
} catch (final RuntimeException e) {
|
||||
return new AdapterInfo(new AdaptationResult(AdaptationResult.Outcome.ERROR_OTHER, Arrays.toString(types), e.toString()));
|
||||
}
|
||||
}
|
||||
}, CREATE_ADAPTER_INFO_ACC_CTXT);
|
||||
|
||||
@ -141,6 +141,7 @@ type.error.extend.ERROR_NO_ACCESSIBLE_CONSTRUCTOR=Can not extend class {0} as it
|
||||
type.error.extend.ERROR_MULTIPLE_SUPERCLASSES=Can not extend multiple classes {0}. At most one of the specified types can be a class, the rest must all be interfaces.
|
||||
type.error.extend.ERROR_NO_COMMON_LOADER=Can not find a common class loader for ScriptObject and {0}.
|
||||
type.error.extend.ERROR_FINAL_FINALIZER=Can not extend class because {0} has a final finalize method.
|
||||
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.method.not.constructor=Java method {0} cannot be used as a constructor.
|
||||
|
||||
42
nashorn/test/script/basic/JDK-8068580.js
Normal file
42
nashorn/test/script/basic/JDK-8068580.js
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2014 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-8068580: make JavaAdapterFactory.isAutoConvertibleFromFunction more robust
|
||||
*
|
||||
* @test
|
||||
* @run
|
||||
*/
|
||||
|
||||
var BigAbstract = Java.type("jdk.nashorn.test.models.BigAbstract")
|
||||
try {
|
||||
new BigAbstract({});
|
||||
} catch (e) {
|
||||
Assert.assertTrue(e instanceof TypeError);
|
||||
Assert.assertEquals(e.message, "Can not extend/implement [class jdk.nashorn.test.models.BigAbstract] because of java.lang.RuntimeException: Method code too large!");
|
||||
}
|
||||
try {
|
||||
BigAbstract.accept(function() { });
|
||||
} catch (e) {
|
||||
Assert.assertSame(e.class, java.lang.ClassCastException.class);
|
||||
}
|
||||
4709
nashorn/test/src/jdk/nashorn/test/models/BigAbstract.java
Normal file
4709
nashorn/test/src/jdk/nashorn/test/models/BigAbstract.java
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user