java.lang.ClassFormatError: Illegal field modifiers in class

送分小仙女□ 提交于 2019-12-14 01:22:30

问题


I am trying to implement a simple TabGroup using environmental services. My code looks like this:

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;
   }

}

When this code is executed, it throws following exception:

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

I found part of the answer in the old thread: "... an interface like this should not be in the components package to begin with."

My question is then: where should I move TabContext interface?

Following the rule#1 I am posting the entire stack trace:

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)

回答1:


There are big bright warning signs in Tapestry: only components go in the components package. TabContext is an interface, it doesn't belong there. Tapestry is tripping up, trying to convert this into a component by rewriting its bytecode. Move this interface to a non-managed package.




回答2:


What you are looking at probably has nothing to do with concrete "@Environmental" injection.

What your JVM is telling you is that something is seriously wrong with your class file (the bytecode).

I don't know much about Tapestry in detail but it seems that it's doing some nasty byte-code manipulation when classes are loaded to make annotations work (org.apache.tapestry5.internal.plastic.PlasticClassPool.loadAndTransformClass).

I would suggest the following however:

  • switch to latest version of SUN JDK (e.g. if you are running OpenJDK, it might be that Tapestry is not throughly tested on this JVM)
  • switch to latest version of Tapestry (if you are already on it, try downgrading) -- there might be a bug in bytecode produced by Tapestry


来源:https://stackoverflow.com/questions/18727105/java-lang-classformaterror-illegal-field-modifiers-in-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!