About

Jadira is the home for Sousan and Chris Pheby's open source projects. These are reusable open source Java modules that provide first class solutions using the most effective current JEE technologies.

Search
Tag Cloud
...
Login

Jadira Support > defaultZoneTL not found in java.util.TimeZone

Hi,

Running:

$ java -version
java version "1.7.0_17"
Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

I'm getting this error whilst trying to access a field (defined thus):

@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTimeWithZone")
@Columns(columns = {
@Column(nullable = false, updatable = false, name = "createdDateTime"),
@Column(nullable = false, updatable = false, name = "createdDateTimeTimeZone")})
@NotNull(message = "{abstractModel.createdDateTime.notNull}", groups = TimeAwareValidationGroup.class)
private DateTime createdDateTime;

Exception:

java.lang.IllegalStateException: Field (defaultZoneTL) could not be found in java.util.TimeZone
at org.jadira.usertype.spi.reflectionutils.ReflectionUtils.findField(ReflectionUtils.java:43) ~[usertype.spi-3.0.0.CR2.jar:na]
at org.jadira.usertype.spi.reflectionutils.JavaTimeZoneWorkaroundHelper.<clinit>(JavaTimeZoneWorkaroundHelper.java:8) ~[usertype.spi-3.0.0.CR2.jar:na]
Wrapped by: java.lang.ExceptionInInitializerError: null
at org.jadira.usertype.spi.shared.AbstractUserType.beforeNullSafeOperation(AbstractUserType.java:84) ~[usertype.spi-3.0.0.CR2.jar:na]
at org.jadira.usertype.spi.shared.AbstractMultiColumnUserType.nullSafeGet(AbstractMultiColumnUserType.java:93) ~[usertype.spi-3.0.0.CR2.jar:na]
at org.hibernate.type.CompositeCustomType.nullSafeGet(CompositeCustomType.java:211) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final]
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:106) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final]

I've had a look into the TimeZone class and there is no field called defaultTL.

Any ideas?

-=david=-

April 9, 2013 | Unregistered CommenterDavid Harrigan

Hi,

I meant defaultZoneTL in last sentence.

It looks perhapst that the name of the "property" has been changed to defaultZone without the TL at the end (in java.util.TimeZone)

-=david=-

April 9, 2013 | Unregistered CommenterDavid Harrigan

Hi,

The defaultZoneTL was removed from JDK6u25.

It appears that Jadira is broken for these versions and Java 7 when using Timezones.

-=david=-

April 9, 2013 | Unregistered CommenterDavid Harrigan

Sorry,

JDK6u25 is the build, it's actually update 31 of Java that broke it (also not part of Java 7)

-=david=-

April 9, 2013 | Unregistered CommenterDavid Harrigan

Hi,

Wrote a bit of code to support Java 7 (and Java 6 update 31) only. It would need to be adapted to work with prior versions:


public class JavaTimeZoneWorkaroundHelper {

private static Method GET_DEFAULT_APP_CONTEXT = ReflectionUtils.findMethod(TimeZone.class, "getDefaultInAppContext");
private static Method SET_DEFAULT_APP_CONTEXT = ReflectionUtils.findMethod(TimeZone.class, "setDefaultInAppContext", TimeZone.class);

static {
GET_DEFAULT_APP_CONTEXT.setAccessible(true);
SET_DEFAULT_APP_CONTEXT.setAccessible(true);
}

private static final ThreadLocal<TimeZone> OLD_ZONE = new ThreadLocal<>();

@SuppressWarnings("unchecked")
public static void setTimeZone(final TimeZone zone) {
TimeZone defaultTimeZone = null;
try {
defaultTimeZone = (TimeZone) GET_DEFAULT_APP_CONTEXT.invoke(null);
} catch (IllegalArgumentException e) {
throw new ReflectionException("Cannot reset timezone to avoid JDK JDBC Timezone issue", e);
} catch (IllegalAccessException e) {
throw new ReflectionException("Cannot reset timezone to avoid JDK JDBC Timezone issue", e);
} catch (InvocationTargetException e) {
throw new ReflectionException("Cannot reset timezone to avoid JDK JDBC Timezone issue", e);
}
OLD_ZONE.set(defaultTimeZone);
try {
SET_DEFAULT_APP_CONTEXT.invoke(null, zone);
} catch (IllegalAccessException e) {
throw new ReflectionException("Cannot reset timezone to avoid JDK JDBC Timezone issue", e);
} catch (InvocationTargetException e) {
throw new ReflectionException("Cannot reset timezone to avoid JDK JDBC Timezone issue", e);
}
}

@SuppressWarnings("unchecked")
public static void unsetTimeZone() {
try {
final TimeZone timeZone = OLD_ZONE.get();
SET_DEFAULT_APP_CONTEXT.invoke(null, timeZone);
} catch (IllegalArgumentException e) {
throw new ReflectionException("Cannot reset timezone to avoid JDK JDBC Timezone issue", e);
} catch (IllegalAccessException e) {
throw new ReflectionException("Cannot reset timezone to avoid JDK JDBC Timezone issue", e);
} catch (InvocationTargetException e) {
throw new ReflectionException("Cannot reset timezone to avoid JDK JDBC Timezone issue", e);
}
}
}

Perhaps you might find this useful.

-=david=-

April 9, 2013 | Unregistered CommenterDavid Harrigan

Thanks for the information. I think this issue is one that was actually fixed some time ago. Can you try updating to 3.0.0.GA or later version?

April 15, 2013 | Registered CommenterChris