8068580: make JavaAdapterFactory.isAutoConvertibleFromFunction more robust

Reviewed-by: lagergren, sundar
This commit is contained in:
Attila Szegedi 2015-01-12 11:29:42 +01:00
parent dc2d8b7e11
commit faf445e144
5 changed files with 4761 additions and 15 deletions

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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.

View 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);
}

File diff suppressed because it is too large Load Diff