8214170: ResourceBundle.Control.newBundle should throw IllegalAccessException when constructor of the resource bundle is not public
Reviewed-by: rriggs, mchung
This commit is contained in:
parent
bddbbd85f9
commit
5fc8ae7c71
@ -3184,10 +3184,16 @@ public abstract class ResourceBundle {
|
||||
bundleClass.getName() + " in " + m.toString());
|
||||
}
|
||||
try {
|
||||
// bundle in a unnamed module
|
||||
Constructor<ResourceBundle> ctor = bundleClass.getConstructor();
|
||||
Constructor<ResourceBundle> ctor = AccessController.doPrivileged(
|
||||
new PrivilegedExceptionAction<>() {
|
||||
@Override
|
||||
public Constructor<ResourceBundle> run() throws NoSuchMethodException {
|
||||
return bundleClass.getDeclaredConstructor();
|
||||
}
|
||||
});
|
||||
if (!Modifier.isPublic(ctor.getModifiers())) {
|
||||
return null;
|
||||
throw new IllegalAccessException("no-arg constructor in " +
|
||||
bundleClass.getName() + " is not publicly accessible.");
|
||||
}
|
||||
|
||||
// java.base may not be able to read the bundleClass's module.
|
||||
@ -3196,12 +3202,16 @@ public abstract class ResourceBundle {
|
||||
bundle = ctor.newInstance((Object[]) null);
|
||||
} catch (InvocationTargetException e) {
|
||||
uncheckedThrow(e);
|
||||
} catch (PrivilegedActionException e) {
|
||||
assert e.getException() instanceof NoSuchMethodException;
|
||||
throw new InstantiationException("public no-arg constructor " +
|
||||
"does not exist in " + bundleClass.getName());
|
||||
}
|
||||
} else {
|
||||
throw new ClassCastException(c.getName()
|
||||
+ " cannot be cast to ResourceBundle");
|
||||
}
|
||||
} catch (ClassNotFoundException|NoSuchMethodException e) {
|
||||
} catch (ClassNotFoundException e) {
|
||||
}
|
||||
} else if (format.equals("java.properties")) {
|
||||
final String resourceName = toResourceName0(bundleName, "properties");
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2007, 2018, 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
|
||||
@ -35,6 +35,7 @@ public class MissingResourceCauseTest {
|
||||
callGetBundle("AbstractRB", InstantiationException.class);
|
||||
callGetBundle("BadStaticInitRB", ExceptionInInitializerError.class);
|
||||
callGetBundle("UnreadableRB", IOException.class);
|
||||
callGetBundle("NoNoArgConstructorRB", InstantiationException.class);
|
||||
}
|
||||
|
||||
private static void callGetBundle(String baseName,
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 2007, 2018, 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
|
||||
@ -28,30 +28,29 @@
|
||||
# shared with other test cases.)
|
||||
# @build MissingResourceCauseTest
|
||||
# @build NonResourceBundle PrivateConstructorRB AbstractRB BadStaticInitRB
|
||||
# NoNoArgConstructorRB
|
||||
# @run shell MissingResourceCauseTest.sh
|
||||
|
||||
case "`uname`" in
|
||||
Windows*)
|
||||
DEL=";";
|
||||
Windows* | CYGWIN*)
|
||||
exit 0;
|
||||
;;
|
||||
*)
|
||||
DEL=":";
|
||||
PS="/";
|
||||
;;
|
||||
esac
|
||||
|
||||
#
|
||||
# Create an unreadble properties file
|
||||
#
|
||||
UNREADABLE=UnreadableRB.properties
|
||||
UNREADABLE=${TESTCLASSPATH}${PS}UnreadableRB.properties
|
||||
rm -f $UNREADABLE
|
||||
echo "type=unreadable" >$UNREADABLE
|
||||
chmod 000 $UNREADABLE
|
||||
|
||||
: ${TESTCLASS:=.}
|
||||
: ${TESTSRC:=.}
|
||||
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} -esa -cp ${TESTCLASS}${DEL}${TESTSRC} MissingResourceCauseTest
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} -esa -cp ${TESTCLASSES}${DEL}${TESTSRC} MissingResourceCauseTest
|
||||
STATUS=$?
|
||||
chmod 666 $UNREADABLE
|
||||
rm -f $UNREADABLE
|
||||
exit $?
|
||||
exit $STATUS
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 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.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class NoNoArgConstructorRB extends ListResourceBundle {
|
||||
public NoNoArgConstructorRB(Object o) {
|
||||
}
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "type", "class (no no-arg constructor)" }
|
||||
};
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user