4

我正在尝试使用环境服务实现一个简单的 TabGroup 。我的代码如下所示:

public class TabPanel
{
  ...
  @Inject
  private Environment environment;
  ...
  void beginRender()
  {
      environment.push(TabContext.class, new TabContext()
      {

          public boolean isActiveTab(String tabId)
          {
             return active != null && active.equals(tabId);
          }

      });
   }

}


public interface TabContext
{
   boolean isActiveTab(String tabId);
}


public class Tab
{
   ...
   @Environmental
   private TabContext tabContext;

   @Inject
   private ComponentResources resources;
   ...

   private boolean isActiveAndEnabled()
   {
      return tabContext.isActiveTab(resources.getId()) && !disabled;
   }

}

执行此代码时,会引发以下异常:

java.lang.ClassFormatError: Illegal field modifiers in class TabContext

我在旧线程中找到了部分答案:“......这样的接口不应该在组件包中开始。”

那么我的问题是:我应该将 TabContext 接口移到哪里?

按照规则#1,我发布了整个堆栈跟踪:

java.lang.ClassFormatError: Illegal field modifiers in class com/nhl/link/gms/confirm/components/TabContext: 0x12
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:465)
    at org.apache.tapestry5.internal.plastic.PlasticClassLoader.defineClassWithBytecode(PlasticClassLoader.java:52)
    at org.apache.tapestry5.internal.plastic.PlasticClassPool.realize(PlasticClassPool.java:144)
    at org.apache.tapestry5.internal.plastic.PlasticClassPool.realizeTransformedClass(PlasticClassPool.java:122)
    at org.apache.tapestry5.internal.plastic.PlasticClassImpl.createInstantiator(PlasticClassImpl.java:358)
    at org.apache.tapestry5.internal.plastic.PlasticClassPool.loadAndTransformClass(PlasticClassPool.java:350)
    at org.apache.tapestry5.internal.plastic.PlasticClassLoader.loadClass(PlasticClassLoader.java:38)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:249)
    at org.apache.tapestry5.internal.plastic.PlasticInternalUtils.toClass(PlasticInternalUtils.java:305)
    at org.apache.tapestry5.internal.services.ComponentClassCacheImpl.lookupClassForType(ComponentClassCacheImpl.java:78)
    at org.apache.tapestry5.internal.services.ComponentClassCacheImpl.forName(ComponentClassCacheImpl.java:65)
    at $ComponentClassCache_13229db142809f84.forName(Unknown Source)
    at org.apache.tapestry5.internal.transform.EnvironmentalWorker.transform(EnvironmentalWorker.java:91)
    at org.apache.tapestry5.internal.transform.EnvironmentalWorker.transform(EnvironmentalWorker.java:79)
    at $ComponentClassTransformWorker2_13229db142809fd5.transform(Unknown Source)
    at $ComponentClassTransformWorker2_13229db142809fc9.transform(Unknown Source)
    at org.apache.tapestry5.internal.services.ComponentInstantiatorSourceImpl$3.run(ComponentInstantiatorSourceImpl.java:326)
    at org.apache.tapestry5.ioc.internal.OperationTrackerImpl$1.invoke(OperationTrackerImpl.java:51)
    at org.apache.tapestry5.ioc.internal.OperationTrackerImpl$1.invoke(OperationTrackerImpl.java:48)
    at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74)
    at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.run(OperationTrackerImpl.java:47)
    at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.run(PerThreadOperationTracker.java:76)
    at org.apache.tapestry5.ioc.internal.RegistryImpl.run(RegistryImpl.java:1116)
    at org.apache.tapestry5.internal.services.ComponentInstantiatorSourceImpl.transform(ComponentInstantiatorSourceImpl.java:279)
    at org.apache.tapestry5.internal.plastic.PlasticClassPool.loadAndTransformClass(PlasticClassPool.java:348)
    at org.apache.tapestry5.internal.plastic.PlasticClassLoader.loadClass(PlasticClassLoader.java:38)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at org.apache.tapestry5.internal.plastic.PlasticClassPool.getClassInstantiator(PlasticClassPool.java:516)
    at org.apache.tapestry5.plastic.PlasticManager.getClassInstantiator(PlasticManager.java:189)
    at org.apache.tapestry5.internal.services.ComponentInstantiatorSourceImpl$2.invoke(ComponentInstantiatorSourceImpl.java:235)
    at org.apache.tapestry5.internal.services.ComponentInstantiatorSourceImpl$2.invoke(ComponentInstantiatorSourceImpl.java:229)
    at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74)
    at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
    at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1121)
    at org.apache.tapestry5.internal.services.ComponentInstantiatorSourceImpl.createInstantiatorForClass(ComponentInstantiatorSourceImpl.java:227)
    at org.apache.tapestry5.internal.services.ComponentInstantiatorSourceImpl.getInstantiator(ComponentInstantiatorSourceImpl.java:217)
    at $ComponentInstantiatorSource_13229db142809fc8.getInstantiator(Unknown Source)
    at org.apache.tapestry5.internal.pageload.EmbeddedComponentAssemblerImpl.getModel(EmbeddedComponentAssemblerImpl.java:178)
    at org.apache.tapestry5.internal.pageload.EmbeddedComponentAssemblerImpl.<init>(EmbeddedComponentAssemblerImpl.java:84)
    at org.apache.tapestry5.internal.pageload.ComponentAssemblerImpl.createEmbeddedAssembler(ComponentAssemblerImpl.java:300)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.startComponent(PageLoaderImpl.java:730)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.component(PageLoaderImpl.java:608)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.processTemplateToken(PageLoaderImpl.java:431)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.component(PageLoaderImpl.java:629)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.processTemplateToken(PageLoaderImpl.java:431)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.element(PageLoaderImpl.java:666)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.processTemplateToken(PageLoaderImpl.java:426)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.element(PageLoaderImpl.java:666)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.processTemplateToken(PageLoaderImpl.java:426)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.element(PageLoaderImpl.java:666)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.processTemplateToken(PageLoaderImpl.java:426)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.element(PageLoaderImpl.java:666)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.processTemplateToken(PageLoaderImpl.java:426)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.element(PageLoaderImpl.java:666)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.processTemplateToken(PageLoaderImpl.java:426)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.element(PageLoaderImpl.java:666)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.processTemplateToken(PageLoaderImpl.java:426)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.programAssembler(PageLoaderImpl.java:267)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.access$1000(PageLoaderImpl.java:67)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl$4.invoke(PageLoaderImpl.java:239)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl$4.invoke(PageLoaderImpl.java:222)
    at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74)
    at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
    at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1121)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.createAssembler(PageLoaderImpl.java:221)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.getAssembler(PageLoaderImpl.java:211)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl$12.execute(PageLoaderImpl.java:928)
    at org.apache.tapestry5.internal.pageload.ComponentAssemblerImpl.runActions(ComponentAssemblerImpl.java:235)
    at org.apache.tapestry5.internal.pageload.ComponentAssemblerImpl.performAssembleRootComponent(ComponentAssemblerImpl.java:113)
    at org.apache.tapestry5.internal.pageload.ComponentAssemblerImpl.access$000(ComponentAssemblerImpl.java:40)
    at org.apache.tapestry5.internal.pageload.ComponentAssemblerImpl$1.invoke(ComponentAssemblerImpl.java:88)
    at org.apache.tapestry5.internal.pageload.ComponentAssemblerImpl$1.invoke(ComponentAssemblerImpl.java:85)
    at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74)
    at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
    at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1121)
    at org.apache.tapestry5.internal.pageload.ComponentAssemblerImpl.assembleRootComponent(ComponentAssemblerImpl.java:83)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl$3.invoke(PageLoaderImpl.java:185)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl$3.invoke(PageLoaderImpl.java:178)
    at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74)
    at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
    at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1121)
    at org.apache.tapestry5.internal.pageload.PageLoaderImpl.loadPage(PageLoaderImpl.java:177)
    at $PageLoader_13229db142809fe7.loadPage(Unknown Source)
    at org.apache.tapestry5.internal.services.PageSourceImpl.getPage(PageSourceImpl.java:104)
    at $PageSource_13229db142809fe4.getPage(Unknown Source)
    at org.apache.tapestry5.internal.services.NonPoolingRequestPageCacheImpl.get(NonPoolingRequestPageCacheImpl.java:82)
    at $RequestPageCache_13229db142809fe3.get(Unknown Source)
    at $RequestPageCache_13229db142809fde.get(Unknown Source)
    at org.apache.tapestry5.internal.services.PageRenderRequestHandlerImpl.handle(PageRenderRequestHandlerImpl.java:55)
    at org.apache.tapestry5.services.TapestryModule$37.handle(TapestryModule.java:2208)
    at $PageRenderRequestHandler_13229db142809fe2.handle(Unknown Source)
    at $PageRenderRequestHandler_13229db142809fdc.handle(Unknown Source)
    at org.apache.tapestry5.internal.services.ComponentRequestHandlerTerminator.handlePageRender(ComponentRequestHandlerTerminator.java:48)
    at org.apache.tapestry5.services.InitializeActivePageName.handlePageRender(InitializeActivePageName.java:47)
    at $ComponentRequestHandler_13229db142809fdd.handlePageRender(Unknown Source)
    at $ComponentRequestHandler_13229db142809fac.handlePageRender(Unknown Source)
    at org.apache.tapestry5.internal.services.PageRenderDispatcher.dispatch(PageRenderDispatcher.java:45)
    at $Dispatcher_13229db142809faf.dispatch(Unknown Source)
    at $Dispatcher_13229db142809fa9.dispatch(Unknown Source)
    at org.apache.tapestry5.services.TapestryModule$RequestHandlerTerminator.service(TapestryModule.java:302)
    at org.apache.tapestry5.internal.services.RequestErrorFilter.service(RequestErrorFilter.java:26)
    at $RequestHandler_13229db142809faa.service(Unknown Source)
    at org.apache.tapestry5.services.TapestryModule$3.service(TapestryModule.java:902)
    at $RequestHandler_13229db142809faa.service(Unknown Source)
    at org.apache.tapestry5.services.TapestryModule$2.service(TapestryModule.java:892)
    at $RequestHandler_13229db142809faa.service(Unknown Source)
    at org.apache.tapestry5.internal.services.StaticFilesFilter.service(StaticFilesFilter.java:90)
    at $RequestHandler_13229db142809faa.service(Unknown Source)
    at $RequestHandler_13229db142809f9f.service(Unknown Source)
    at org.apache.tapestry5.services.TapestryModule$HttpServletRequestHandlerTerminator.service(TapestryModule.java:253)
    at org.apache.tapestry5.internal.gzip.GZipFilter.service(GZipFilter.java:53)
    at $HttpServletRequestHandler_13229db142809fa1.service(Unknown Source)
    at org.apache.tapestry5.internal.services.IgnoredPathsFilter.service(IgnoredPathsFilter.java:62)
    at $HttpServletRequestFilter_13229db142809f9d.service(Unknown Source)
    at $HttpServletRequestHandler_13229db142809fa1.service(Unknown Source)
    at org.apache.tapestry5.services.TapestryModule$1.service(TapestryModule.java:852)
    at $HttpServletRequestHandler_13229db142809fa1.service(Unknown Source)
    at $HttpServletRequestHandler_13229db142809f9b.service(Unknown Source)
    at org.apache.tapestry5.TapestryFilter.doFilter(TapestryFilter.java:171)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1338)
    at com.nhl.link.framework.servlet.LogFilter.doFilter(LogFilter.java:77)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1338)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:484)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1065)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:413)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:192)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:999)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:250)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111)
    at org.eclipse.jetty.server.Server.handle(Server.java:350)
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:454)
    at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:890)
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:944)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:630)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:230)
    at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:77)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:620)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:46)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:603)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:538)
    at java.lang.Thread.run(Thread.java:680)
4

2 回答 2

10

Tapestry 中有大而明亮的警告标志:组件包中只有组件。TabContext 是一个接口,它不属于那里。Tapestry 正在跳闸,试图通过重写其字节码将其转换为组件。将此接口移至非受管软件包。

于 2013-09-10T22:25:20.640 回答
0

您正在查看的内容可能与具体的“@Environmental”注入无关。

您的 JVM 告诉您的是您的类文件(字节码)有严重问题。

我对 Tapestry 不太了解,但它似乎在加载类以使注释工作时进行了一些讨厌的字节码操作(org.apache.tapestry5.internal.plastic.PlasticClassPool.loadAndTransformClass)。

但是,我建议以下内容:

  • 切换到最新版本的 SUN JDK(例如,如果您正在运行 OpenJDK,可能是 Tapestry 没有在这个 JVM 上经过全面测试)
  • 切换到最新版本的 Tapestry(如果您已经在上面,请尝试降级)—— Tapestry 生成的字节码中可能存在错误
于 2013-09-10T19:50:14.727 回答