ICU-7305 Fixed some test problem under Java security manager enabled.

X-SVN-Rev: 27345
This commit is contained in:
Yoshito Umaoka 2010-01-20 17:50:58 +00:00
parent 513cc2bc2b
commit cfd92fecdc
3 changed files with 31 additions and 9 deletions

View File

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 2008, International Business Machines Corporation and *
* Copyright (C) 2008-2010, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -8,6 +8,9 @@ package com.ibm.icu.impl;
import java.io.IOException;
import java.io.InputStream;
import java.security.AccessControlException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.MissingResourceException;
import java.util.Properties;
@ -50,11 +53,20 @@ public class ICUConfig {
*/
public static String get(String name, String def) {
String val = null;
// Try the system property first
try {
final String fname = name;
if (System.getSecurityManager() != null) {
try {
val = AccessController.doPrivileged(new PrivilegedAction<String>() {
public String run() {
return System.getProperty(fname);
}
});
} catch (AccessControlException e) {
// ignore
// TODO log this message
}
} else {
val = System.getProperty(name);
} catch (SecurityException e) {
// Ignore and fall through
}
if (val == null) {

View File

@ -1,6 +1,6 @@
//#
//#*******************************************************************************
//#* Copyright (C) 1997-2009, International Business Machines Corporation and *
//#* Copyright (C) 1997-2010, International Business Machines Corporation and *
//#* others. All Rights Reserved. *
//#*******************************************************************************
//#* This is the ant build file for ICU4J. See readme.html for more information.
@ -22,6 +22,9 @@ grant
// IBM 1.6 on Windows does not allow to use reflection to access
// getDSTSavings in TimeZone implementation class in sun.util.clanedar.
permission java.lang.RuntimePermission "accessClassInPackage.sun.util.calendar";
// for testing lenient decimal/group separator parsing
permission java.util.PropertyPermission "com.ibm.icu.text.DecimalFormat.SkipExtendedSeparatorParsing", "write";
};
// there must be a way for code in one jar file to call code in another jar
@ -38,6 +41,9 @@ grant codebase "file:${user.dir}/icu4j.jar"
{
permission java.io.FilePermission "${/}${user.dir}${/}icu4jtests.jar", "read";
permission java.io.FilePermission "${/}${user.dir}${/}icu4j-charsets.jar", "read";
permission java.util.PropertyPermission "com.ibm.icu.util.TimeZone.DefaultTimeZoneType", "read";
permission java.util.PropertyPermission "com.ibm.icu.text.DecimalFormat.SkipExtendedSeparatorParsing", "read";
};
grant codebase "file:${user.dir}/icu4jtests.jar"

View File

@ -1,6 +1,6 @@
/**
*******************************************************************************
* Copyright (C) 2000-2009, International Business Machines Corporation and *
* Copyright (C) 2000-2010, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -17,6 +17,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.security.AccessControlException;
import java.util.Date;
import java.util.Locale;
@ -39,8 +40,11 @@ public class TimeZoneRegression extends TestFmwk {
logln("*** CHECK TIMEZONE AGAINST HOST OS SETTING ***");
String id = TimeZone.getDefault().getID();
try {
// user.timezone is a protected system property
logln("user.timezone: " + System.getProperty("user.timezone", "<not set>"));
try {
logln("user.timezone: " + System.getProperty("user.timezone", "<not set>"));
} catch (AccessControlException e) {
// user.timezone is a protected system property - ignore
}
logln("TimeZone.getDefault().getID(): " + id);
logln(new Date().toString());
logln("*** THE RESULTS OF THIS TEST MUST BE VERIFIED MANUALLY ***");