You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by cl...@apache.org on 2007/10/19 22:55:26 UTC
svn commit: r586609 - in /db/jdo/trunk: api2-legacy/src/java/javax/jdo/spi/
api2-legacy/test/java/javax/jdo/identity/ api2/src/java/javax/jdo/spi/
api2/test/java/javax/jdo/identity/
Author: clr
Date: Fri Oct 19 13:55:25 2007
New Revision: 586609
URL: http://svn.apache.org/viewvc?rev=586609&view=rev
Log:
JDO-544 NullPointerException running with SecurityManager
Modified:
db/jdo/trunk/api2-legacy/src/java/javax/jdo/spi/JDOImplHelper.java
db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/ObjectIdentityTest.java
db/jdo/trunk/api2/src/java/javax/jdo/spi/JDOImplHelper.java
db/jdo/trunk/api2/test/java/javax/jdo/identity/ObjectIdentityTest.java
Modified: db/jdo/trunk/api2-legacy/src/java/javax/jdo/spi/JDOImplHelper.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/src/java/javax/jdo/spi/JDOImplHelper.java?rev=586609&r1=586608&r2=586609&view=diff
==============================================================================
--- db/jdo/trunk/api2-legacy/src/java/javax/jdo/spi/JDOImplHelper.java (original)
+++ db/jdo/trunk/api2-legacy/src/java/javax/jdo/spi/JDOImplHelper.java Fri Oct 19 13:55:25 2007
@@ -26,6 +26,9 @@
import java.lang.reflect.Constructor;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
@@ -120,7 +123,7 @@
/** Register the default DateFormat instance.
*/
static {
- jdoImplHelper.registerDateFormat(DateFormat.getDateTimeInstance());
+ jdoImplHelper.registerDateFormat(getDateTimeInstance());
}
/** Creates new JDOImplHelper */
@@ -794,10 +797,39 @@
}
/**
+ * Get the DateFormat instance for the default locale from the VM.
+ * This requires the following privileges for JDOImplHelper in the
+ * security permissions file:
+ * permission java.util.PropertyPermission "user.country", "read";
+ * permission java.util.PropertyPermission "user.timezone", "read,write";
+ * permission java.util.PropertyPermission "java.home", "read";
+ * If these permissions are not present, or there is some other
+ * problem getting the default date format, a simple formatter is returned.
+ * @since 2.1
+ * @return the default date-time formatter
+ */
+ static DateFormat getDateTimeInstance() {
+ DateFormat result = null;
+ try {
+ result = (DateFormat) AccessController.doPrivileged (
+ new PrivilegedAction () {
+ public Object run () {
+ return DateFormat.getDateTimeInstance();
+ }
+ }
+ );
+ } catch (Exception ex) {
+ result = DateFormat.getInstance();
+ }
+ return result;
+ }
+
+ /**
* Register a DateFormat instance for use with constructing Date
* instances. The default is the default DateFormat instance.
* If the new instance implements SimpleDateFormat, get its pattern
* for error messages.
+ * @since 2.0
* @param df the DateFormat instance to use
*/
public synchronized void registerDateFormat(DateFormat df) {
Modified: db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/ObjectIdentityTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/ObjectIdentityTest.java?rev=586609&r1=586608&r2=586609&view=diff
==============================================================================
--- db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/ObjectIdentityTest.java (original)
+++ db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/ObjectIdentityTest.java Fri Oct 19 13:55:25 2007
@@ -237,6 +237,14 @@
"java.util.Date:" + rightNow);
}
+ public void testStringNullDateConstructor() {
+ // this test uses the standard date-time format
+ // "M/d/yy h:mm a"
+ helper.registerDateFormat(DateFormat.getInstance());
+ Object c1 = new ObjectIdentity(Object.class,
+ "java.util.Date:" + "10/9/2007 4:26 PM");
+ }
+
public void testBadStringDateConstructor() {
try {
ObjectIdentity c1 = new ObjectIdentity(Object.class,
Modified: db/jdo/trunk/api2/src/java/javax/jdo/spi/JDOImplHelper.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/src/java/javax/jdo/spi/JDOImplHelper.java?rev=586609&r1=586608&r2=586609&view=diff
==============================================================================
--- db/jdo/trunk/api2/src/java/javax/jdo/spi/JDOImplHelper.java (original)
+++ db/jdo/trunk/api2/src/java/javax/jdo/spi/JDOImplHelper.java Fri Oct 19 13:55:25 2007
@@ -26,6 +26,9 @@
import java.lang.reflect.Constructor;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
@@ -120,7 +123,7 @@
/** Register the default DateFormat instance.
*/
static {
- jdoImplHelper.registerDateFormat(DateFormat.getDateTimeInstance());
+ jdoImplHelper.registerDateFormat(getDateTimeInstance());
}
/** Creates new JDOImplHelper */
@@ -794,10 +797,39 @@
}
/**
+ * Get the DateFormat instance for the default locale from the VM.
+ * This requires the following privileges for JDOImplHelper in the
+ * security permissions file:
+ * permission java.util.PropertyPermission "user.country", "read";
+ * permission java.util.PropertyPermission "user.timezone", "read,write";
+ * permission java.util.PropertyPermission "java.home", "read";
+ * If these permissions are not present, or there is some other
+ * problem getting the default date format, a simple formatter is returned.
+ * @since 2.1
+ * @return the default date-time formatter
+ */
+ static DateFormat getDateTimeInstance() {
+ DateFormat result = null;
+ try {
+ result = (DateFormat) AccessController.doPrivileged (
+ new PrivilegedAction () {
+ public Object run () {
+ return DateFormat.getDateTimeInstance();
+ }
+ }
+ );
+ } catch (Exception ex) {
+ result = DateFormat.getInstance();
+ }
+ return result;
+ }
+
+ /**
* Register a DateFormat instance for use with constructing Date
* instances. The default is the default DateFormat instance.
* If the new instance implements SimpleDateFormat, get its pattern
* for error messages.
+ * @since 2.0
* @param df the DateFormat instance to use
*/
public synchronized void registerDateFormat(DateFormat df) {
Modified: db/jdo/trunk/api2/test/java/javax/jdo/identity/ObjectIdentityTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/test/java/javax/jdo/identity/ObjectIdentityTest.java?rev=586609&r1=586608&r2=586609&view=diff
==============================================================================
--- db/jdo/trunk/api2/test/java/javax/jdo/identity/ObjectIdentityTest.java (original)
+++ db/jdo/trunk/api2/test/java/javax/jdo/identity/ObjectIdentityTest.java Fri Oct 19 13:55:25 2007
@@ -237,6 +237,14 @@
"java.util.Date:" + rightNow);
}
+ public void testStringNullDateConstructor() {
+ // this test uses the standard date-time format
+ // "M/d/yy h:mm a"
+ helper.registerDateFormat(DateFormat.getInstance());
+ Object c1 = new ObjectIdentity(Object.class,
+ "java.util.Date:" + "10/9/2007 4:26 PM");
+ }
+
public void testBadStringDateConstructor() {
try {
ObjectIdentity c1 = new ObjectIdentity(Object.class,