Kotlin Annotation compiles, but seems error byte code generated

I'm translating ebean-jaxrs to kotlin:

Provider Consumes( MediaType.APPLICATION_JSON ,"text/json") Produces( MediaType.APPLICATION_JSON , "text/json") public class JaxrsJsonProvider : MessageBodyWriter<Any>, MessageBodyReader<Any> { ....

it compiles , but throws following exception when running :

java.lang.annotation.AnnotationTypeMismatchException: Incorrectly typed data found for annotation element public abstract java.lang.String[] javax.ws.rs.Consumes.value() (Found data of type Array with component tag: 115)

at sun.reflect.annotation.AnnotationTypeMismatchExceptionProxy.generateException(AnnotationTypeMismatchExceptionProxy.java:39)

at sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:57)

at $Proxy27.value(Unknown Source)

at com.sun.jersey.core.header.MediaTypes.createMediaTypes(MediaTypes.java:197)

at com.sun.jersey.core.spi.factory.MessageBodyFactory.initReaders(MessageBodyFactory.java:182)

at com.sun.jersey.core.spi.factory.MessageBodyFactory.initReaders(MessageBodyFactory.java:175)

at com.sun.jersey.core.spi.factory.MessageBodyFactory.init(MessageBodyFactory.java:162)

at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1279)

at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:163)

at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:769)

at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:765)

at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)

at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:765)

at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:760)

at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:489)

at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:319)

at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)

at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)

at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)

at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)

at javax.servlet.GenericServlet.init(GenericServlet.java:244)

at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:517)

at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:331)

at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)

at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:747)

at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:263)

at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1238)

at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:706)

at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:480)

at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:293)

at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)

at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)

at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:172)

at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)

at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)

at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)

at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)

at org.eclipse.jetty.server.Server.doStart(Server.java:277)

at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:65)

at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)

at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:511)

at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:364)

at org.mortbay.jetty.plugin.JettyRunMojo.execute(JettyRunMojo.java:516)

at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)

at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)

at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)

at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)

at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)

at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)

at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)

at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)

at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)

at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)

at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)

at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)

at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)

at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)

at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)

at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)

at org.codehaus.classworlds.Launcher.main(Launcher.java:47)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Oct 20, 2012 2:37:14 PM com.sun.jersey.server.impl.cdi.CDIComponentProviderFactoryInitializer initialize

INFO: CDI support is enabled

Oct 20, 2012 2:37:14 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate

INFO: Initiating Jersey application, version 'Jersey: 1.14 09/09/2012 05:39 PM'

The source file and classes are uploaded !

Thanks!

Outersky



jaxrs.kt.zip (4.85 KB)

AbstractEntityResource.class.zip (4.09 KB)

AbstractEntityResource$ClassObject$.class.zip (771 Bytes)

I put the annotation into a java file:

@Provider @Consumes( { MediaType.APPLICATION_JSON, "text/json" }) @Produces( { MediaType.APPLICATION_JSON, "text/json" }) public interface IProvider { }

then in kotlin remove all annotations :
public class JaxrsJsonProvider : MessageBodyWriter<Any>, MessageBodyReader<Any>, IProvider {
....

Still get the simillar error:

java.lang.annotation.AnnotationTypeMismatchException: Incorrectly typed data found for annotation element public abstract java.lang.String[] javax.ws.rs.Consumes.value() (Found data of type Array with component tag: 101) at sun.reflect.annotation.AnnotationTypeMismatchExceptionProxy.generateException(AnnotationTypeMismatchExceptionProxy.java:39) at sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:57) at $Proxy25.value(Unknown Source) at com.sun.jersey.core.header.MediaTypes.createMediaTypes(MediaTypes.java:197) at com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller.addConsumes(IntrospectionModeller.java:158)

So maybe it’s not caused by kotlin . still working on this  :(

Looks like a bug. Please report to the tracker

At last I found out the real cause is : used a static member from java class !

After changed to string literals, everything is ok!

reported here:
KT-2978 Annotation can not use static members from java class