开发者

IllegalAccessException with grails timeZoneSelect tag on google app engine/java

Has anyone used the grails timeZoneSelect tag on GAE/J ? I've come across the error below on app engine. I know reflection is not allowed, but the line in error seems to be calling a straightforward public function (inDaylightTime)? Does anyone know how to workaround this (short of a hardcoded list of time zones)?

thanks

Uncaught exception from servlet
org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error processing GroovyPageView: Error executing tag : org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException: Error executing tag : java.lang.IllegalAccessException: Reflection is not allowed on public boolean sun.util.calendar.ZoneInfo.inDaylightTime(java.util.Date)
    at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:97)
    at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
    at com.google.ap开发者_运维百科phosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:238)
    at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:135)
    at com.google.apphosting.runtime.JavaRuntime.handleRequest(JavaRuntime.java:235)
    at com.google.apphosting.base.RuntimePb$EvaluationRuntime$6.handleBlockingRequest(RuntimePb.java:5235)
    at com.google.apphosting.base.RuntimePb$EvaluationRuntime$6.handleBlockingRequest(RuntimePb.java:5233)
    at com.google.net.rpc.impl.BlockingApplicationHandler.handleRequest(BlockingApplicationHandler.java:24)
    at com.google.net.rpc.impl.RpcUtil.runRpcInApplication(RpcUtil.java:363)
    at com.google.net.rpc.impl.Server$2.run(Server.java:838)
    at com.google.tracing.LocalTraceSpanRunnable.run(LocalTraceSpanRunnable.java:56)
    at com.google.tracing.LocalTraceSpanBuilder.internalContinueSpan(LocalTraceSpanBuilder.java:536)
    at com.google.net.rpc.impl.Server.startRpc(Server.java:793)
    at com.google.net.rpc.impl.Server.processRequest(Server.java:368)
    at com.google.net.rpc.impl.ServerConnection.messageReceived(ServerConnection.java:448)
    at com.google.net.rpc.impl.RpcConnection.parseMessages(RpcConnection.java:319)
    at com.google.net.rpc.impl.RpcConnection.dataReceived(RpcConnection.java:290)
    at com.google.net.async.Connection.handleReadEvent(Connection.java:466)
    at com.google.net.async.EventDispatcher.processNetworkEvents(EventDispatcher.java:759)
    at com.google.net.async.EventDispatcher.internalLoop(EventDispatcher.java:205)
    at com.google.net.async.EventDispatcher.loop(EventDispatcher.java:101)
    at com.google.net.rpc.RpcService.runUntilServerShutdown(RpcService.java:251)
    at com.google.apphosting.runtime.JavaRuntime$RpcRunnable.run(JavaRuntime.java:394)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException: Error executing tag : org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException: Error executing tag : java.lang.IllegalAccessException: Reflection is not allowed on public boolean sun.util.calendar.ZoneInfo.inDaylightTime(java.util.Date)


I had a similar problem when I tried to call TimeZone.getTimeZone() to get a TimeZone and worked around this one by using a different library, Joda Time.

http://joda-time.sourceforge.net/index.html

There are equivalent time/date methods in this package that work better than those in the underlying JDK.


This is specific to dynamic languages which use reflection to invoke methods on the sun.* objects returned by java.util.TimeZone factory methods; I worked around a similar limitation in the TimeZone stuff by writing a wrapper method in Java and then calling that method, so that the invocations on the sun.* objects wouldn't be via reflection.


the below works for me

public Date getDateWithTimeZone(Date date, String timeZone){
    def tz = TimeZone.getTimeZone(timeZone);
    def cal = Calendar.getInstance()
    cal.setTimeInMillis( date.getTime() )
    cal.setTimeZone( tz )
    def offset = cal.get(Calendar.ZONE_OFFSET)
    date.setTime( date.getTime()+offset )
    return date;
}


Here's the Java half of what I did:

package inonit.google.appengine.runtime;

import java.util.*;

public class Methods {
    public int getTimezoneOffset(String timezone, long time) {
        return TimeZone.getTimeZone(timezone).getOffset(time);
    }
}

My application isn't Grails, and I don't know enough about Grails to know whether the abstractions defined by Grails would make it easy to call into a class like this one or not. But in my app I just went on to instantiate a local helper copy of this object and call into it when I needed to calculate timezone offsets.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜