weixin_39603217
2020-12-09 13:18 阅读 6

java.lang.reflect.GenericSignatureFormatError is thrown for web methods with inner classes as type argument

When a web method has a parameter or return value with an inner class as a type argument, java.lang.reflect.GenericSignatureFormatError is thrown when publishing the endpoint.

Example:

public Set testMethod(final Set ids);

After some debugging I think I've tracked down the issue to com.sun.xml.ws.model.FieldSignature.

It looks like the fqcn-method uses '.' instead of '$' as a delimiter for inner classes:

private static String fqcn(Type t) { if (t instanceof Class) { Class c = (Class)t; if (c.getDeclaringClass() == null)

{ return c.getName().replace('.', '/'); } else { return fqcn(c.getDeclaringClass())+"."+c.getSimpleName(); // HERE } } else if (t instanceof ParameterizedType) { ParameterizedType p = (ParameterizedType)t; if (p.getOwnerType() == null) { return fqcn(p.getRawType())+args(p); } else { assert p.getRawType() instanceof Class; return fqcn(p.getOwnerType())+"."+ // AND HERE ((Class)p.getRawType()).getSimpleName()+args(p); } } throw new IllegalArgumentException("Illegal fqcn arg = "+t); }

When patched like this, everything works just fine:

private static String fqcn(Type t) { if (t instanceof Class) { Class c = (Class)t; if (c.getDeclaringClass() == null) { return c.getName().replace('.', '/'); }

else

{ return fqcn(c.getDeclaringClass())+"$"+c.getSimpleName(); }

} else if (t instanceof ParameterizedType) { ParameterizedType p = (ParameterizedType)t; if (p.getOwnerType() == null)

{ return fqcn(p.getRawType())+args(p); }

else

{ assert p.getRawType() instanceof Class; return fqcn(p.getOwnerType())+"$"+ ((Class)p.getRawType()).getSimpleName()+args(p); }

} throw new IllegalArgumentException("Illegal fqcn arg = "+t); }

Attaching a small repro. Expected output:

Exception in thread "main" java.lang.reflect.GenericSignatureFormatError at sun.reflect.generics.parser.SignatureParser.error(SignatureParser.java:103) at sun.reflect.generics.parser.SignatureParser.parseSimpleClassTypeSignature(Signat ureParser.java:262) at sun.reflect.generics.parser.SignatureParser.parseClassTypeSignatureSuffix(Signat ureParser.java:270) at sun.reflect.generics.parser.SignatureParser.parseClassTypeSignature(SignaturePar ser.java:244) at sun.reflect.generics.parser.SignatureParser.parseFieldTypeSignature(SignaturePar ser.java:228) at sun.reflect.generics.parser.SignatureParser.parseTypeArgument(SignatureParser.ja va:319) at sun.reflect.generics.parser.SignatureParser.parseTypeArguments(SignatureParser.j ava:284) at sun.reflect.generics.parser.SignatureParser.parseSimpleClassTypeSignature(Signat ureParser.java:260) at sun.reflect.generics.parser.SignatureParser.parseClassTypeSignatureSuffix(Signat ureParser.java:270) at sun.reflect.generics.parser.SignatureParser.parseClassTypeSignature(SignaturePar ser.java:244) at sun.reflect.generics.parser.SignatureParser.parseFieldTypeSignature(SignaturePar ser.java:228) at sun.reflect.generics.parser.SignatureParser.parseTypeSignature(SignatureParser.j ava:359) at sun.reflect.generics.parser.SignatureParser.parseTypeSig(SignatureParser.java:15 7) at sun.reflect.generics.repository.FieldRepository.parse(FieldRepository.java:34) at sun.reflect.generics.repository.FieldRepository.parse(FieldRepository.java:24) at sun.reflect.generics.repository.AbstractRepository.(AbstractRepository.jav a:56) at sun.reflect.generics.repository.FieldRepository.(FieldRepository.java:30) at sun.reflect.generics.repository.FieldRepository.make(FieldRepository.java:48) at java.lang.reflect.Field.getGenericInfo(Field.java:85) at java.lang.reflect.Field.getGenericType(Field.java:223) at com.sun.xml.bind.v2.model.nav.ReflectionNavigator.getFieldType(ReflectionNavigat or.java:273) at com.sun.xml.bind.v2.model.nav.ReflectionNavigator.getFieldType(ReflectionNavigat or.java:58) at com.sun.xml.bind.v2.model.impl.FieldPropertySeed.getRawType(FieldPropertySeed.ja va:74) at com.sun.xml.bind.v2.model.impl.RuntimeClassInfoImpl$RuntimePropertySeed.getRawTy pe(RuntimeClassInfoImpl.java:315) at com.sun.xml.bind.v2.model.impl.RuntimeClassInfoImpl$RuntimePropertySeed.getRawTy pe(RuntimeClassInfoImpl.java:289) at com.sun.xml.bind.v2.model.impl.PropertyInfoImpl.(PropertyInfoImpl.java:119 ) at com.sun.xml.bind.v2.model.impl.ERPropertyInfoImpl.(ERPropertyInfoImpl.java :53) at com.sun.xml.bind.v2.model.impl.ElementPropertyInfoImpl.(ElementPropertyInf oImpl.java:96) at com.sun.xml.bind.v2.model.impl.RuntimeElementPropertyInfoImpl.(RuntimeElem entPropertyInfoImpl.java:59) at com.sun.xml.bind.v2.model.impl.RuntimeClassInfoImpl.createElementProperty(Runtim eClassInfoImpl.java:165) at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.addProperty(ClassInfoImpl.java:875) at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.findFieldProperties(ClassInfoImpl.j ava:405) at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.getProperties(ClassInfoImpl.java:30 8) at com.sun.xml.bind.v2.model.impl.RuntimeClassInfoImpl.getProperties(RuntimeClassIn foImpl.java:176) at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:243) at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuil der.java:100) at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuil der.java:81) at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:209) at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuil der.java:95) at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuil der.java:81) at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:315) at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:330) at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java: 466) at com.sun.xml.bind.v2.runtime.JAXBContextImpl.(JAXBContextImpl.java:302) at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContext Impl.java:1140) at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:154) at com.sun.xml.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:106) at com.sun.xml.ws.developer.JAXBContextFactory$1.createJAXBContext(JAXBContextFacto ry.java:109) at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:161) at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:154) at java.security.AccessController.doPrivileged(Native Method) at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl .java:153) at com.sun.xml.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java: 94) at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:258) at com.sun.xml.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:338) at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:201) at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:505) at com.sun.xml.ws.transport.http.server.EndpointImpl.createEndpoint(EndpointImpl.ja va:257) at com.sun.xml.ws.transport.http.server.EndpointImpl.publish(EndpointImpl.java:181) at com.sun.xml.ws.spi.ProviderImpl.createAndPublishEndpoint(ProviderImpl.java:123) at com.acme.AWsImpl.main(AWsImpl.java:26)

Environment

Operating System: All Platform: All

Affected Versions

[2.2.3]

该提问来源于开源项目:javaee/metro-jax-ws

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

11条回答 默认 最新

  • weixin_39603217 weixin_39603217 2020-12-09 13:18

    Reported by stoffipop.net

    点赞 评论 复制链接分享
  • weixin_39603217 weixin_39603217 2020-12-09 13:18

    stoffipop.net said: Created an attachment (id=270) Repro, file #1

    点赞 评论 复制链接分享
  • weixin_39603217 weixin_39603217 2020-12-09 13:18

    stoffipop.net said: Created an attachment (id=271) Repro, file #2

    点赞 评论 复制链接分享
  • weixin_39603217 weixin_39603217 2020-12-09 13:18

    jitu.net said: Assigning it to myself

    点赞 评论 复制链接分享
  • weixin_39603217 weixin_39603217 2020-12-09 13:18

    jitu.net said: setting target milestone to 2.2.2

    点赞 评论 复制链接分享
  • weixin_39603217 weixin_39603217 2020-12-09 13:18

    jitu said: targetting for 2.2.3

    点赞 评论 复制链接分享
  • weixin_39603217 weixin_39603217 2020-12-09 13:18

    said: already fixed in 2.2 branch (svn rev 12536)

    点赞 评论 复制链接分享
  • weixin_39603217 weixin_39603217 2020-12-09 13:18

    File: AWs.java Attached By: stoffipop.net

    点赞 评论 复制链接分享
  • weixin_39603217 weixin_39603217 2020-12-09 13:18

    File: AWsImpl.java Attached By: stoffipop.net

    点赞 评论 复制链接分享
  • weixin_39603217 weixin_39603217 2020-12-09 13:18

    This issue was imported from java.net JIRA JAX_WS-845

    点赞 评论 复制链接分享
  • weixin_39603217 weixin_39603217 2020-12-09 13:18

    Marked as fixed on Friday, August 26th 2011, 6:35:05 am

    点赞 评论 复制链接分享

相关推荐