java.lang.RuntimeException: Failed to serialize com.example.MyBuild#detailsMap for class com.example.MyBuild

Jenkins JIRA | Mike Dillon | 7 years ago
  1. 0

    Under some circumstances, the "core" field of a hudson.util.CopyOnWriteMap.Tree instance can be an instance of java.util.Collections.EmptyMap, which is not a subclass of TreeMap. When this happens, the following error is seen during serialization: {noformat} 2010-02-25 00:43:09,238 ERROR [hudson.model.Executor] Executor throw an exception unexpectedly java.lang.RuntimeException: Failed to serialize com.example.MyBuild#detailsMap for class com.example.MyBuild at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:160) at hudson.util.RobustReflectionConverter$2.visit(RobustReflectionConverter.java:131) at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:130) at hudson.util.RobustReflectionConverter.doMarshal(RobustReflectionConverter.java:116) at hudson.util.RobustReflectionConverter.marshal(RobustReflectionConverter.java:89) at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68) at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:78) at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:63) at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:98) at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:38) at com.thoughtworks.xstream.XStream.marshal(XStream.java:837) at com.thoughtworks.xstream.XStream.marshal(XStream.java:826) at com.thoughtworks.xstream.XStream.toXML(XStream.java:801) at hudson.XmlFile.write(XmlFile.java:161) at hudson.model.Run.save(Run.java:1235) at hudson.model.Run.run(Run.java:1162) at hudson.model.Build.run(Build.java:74) at hudson.model.ResourceController.execute(ResourceController.java:93) at hudson.model.Executor.run(Executor.java:122) Caused by: java.lang.ClassCastException: java.util.Collections$EmptyMap cannot be cast to java.util.TreeMap at com.thoughtworks.xstream.converters.collections.TreeMapConverter.marshal(TreeMapConverter.java:50) at hudson.util.CopyOnWriteMap$Tree$ConverterImpl.marshal(CopyOnWriteMap.java:221) at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68) at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:78) at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:63) at hudson.util.RobustReflectionConverter.marshallField(RobustReflectionConverter.java:168) at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:156) ... 18 more {noformat} It looks like this can happen either when the Tree() or Tree(Comparator) constructors are called or when clear() is called. In those cases, if you don't add any elements, you'll get the wrong kind of map in the core and serialization will fail. The one case that should work is if you do putAll() with an empty Map after creation; that will successfully replace the core with a TreeMap. I've attached a proposed patch. It adds an emptyMap() method to CopyOnWriteMap that is implemented by the two subclasses. All calls that previously went to Collections.emptyMap() now let the subclass decide what type of map to return. It also adds a test for serializing an empty CopyOnWriteMap.Tree. This patch takes the naive approach of creating a new TreeMap every time that emptyMap() is called. It may or not be worthwhile to try to reuse a TreeMap instance for this purpose since CopyOnWriteMap guarantees that the core itself won't be updated.

    Jenkins JIRA | 7 years ago | Mike Dillon
    java.lang.RuntimeException: Failed to serialize com.example.MyBuild#detailsMap for class com.example.MyBuild
  2. 0

    Under some circumstances, the "core" field of a hudson.util.CopyOnWriteMap.Tree instance can be an instance of java.util.Collections.EmptyMap, which is not a subclass of TreeMap. When this happens, the following error is seen during serialization: {noformat} 2010-02-25 00:43:09,238 ERROR [hudson.model.Executor] Executor throw an exception unexpectedly java.lang.RuntimeException: Failed to serialize com.example.MyBuild#detailsMap for class com.example.MyBuild at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:160) at hudson.util.RobustReflectionConverter$2.visit(RobustReflectionConverter.java:131) at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:130) at hudson.util.RobustReflectionConverter.doMarshal(RobustReflectionConverter.java:116) at hudson.util.RobustReflectionConverter.marshal(RobustReflectionConverter.java:89) at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68) at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:78) at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:63) at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:98) at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:38) at com.thoughtworks.xstream.XStream.marshal(XStream.java:837) at com.thoughtworks.xstream.XStream.marshal(XStream.java:826) at com.thoughtworks.xstream.XStream.toXML(XStream.java:801) at hudson.XmlFile.write(XmlFile.java:161) at hudson.model.Run.save(Run.java:1235) at hudson.model.Run.run(Run.java:1162) at hudson.model.Build.run(Build.java:74) at hudson.model.ResourceController.execute(ResourceController.java:93) at hudson.model.Executor.run(Executor.java:122) Caused by: java.lang.ClassCastException: java.util.Collections$EmptyMap cannot be cast to java.util.TreeMap at com.thoughtworks.xstream.converters.collections.TreeMapConverter.marshal(TreeMapConverter.java:50) at hudson.util.CopyOnWriteMap$Tree$ConverterImpl.marshal(CopyOnWriteMap.java:221) at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68) at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:78) at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:63) at hudson.util.RobustReflectionConverter.marshallField(RobustReflectionConverter.java:168) at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:156) ... 18 more {noformat} It looks like this can happen either when the Tree() or Tree(Comparator) constructors are called or when clear() is called. In those cases, if you don't add any elements, you'll get the wrong kind of map in the core and serialization will fail. The one case that should work is if you do putAll() with an empty Map after creation; that will successfully replace the core with a TreeMap. I've attached a proposed patch. It adds an emptyMap() method to CopyOnWriteMap that is implemented by the two subclasses. All calls that previously went to Collections.emptyMap() now let the subclass decide what type of map to return. It also adds a test for serializing an empty CopyOnWriteMap.Tree. This patch takes the naive approach of creating a new TreeMap every time that emptyMap() is called. It may or not be worthwhile to try to reuse a TreeMap instance for this purpose since CopyOnWriteMap guarantees that the core itself won't be updated.

    Jenkins JIRA | 7 years ago | Mike Dillon
    java.lang.RuntimeException: Failed to serialize com.example.MyBuild#detailsMap for class com.example.MyBuild
  3. 0

    GitHub comment 560#144042399

    GitHub | 1 year ago | costin
    java.lang.ClassCastException: java.util.Collections$EmptyMap cannot be cast to org.elasticsearch.hadoop.mr.LinkedMapWritable
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    java.lang.ClassCastException when remote debugging JavaScript application

    Eclipse Bugzilla | 5 years ago | philippe.marschall
    java.lang.ClassCastException: java.util.Collections$EmptyMap cannot be cast to java.lang.Number
  6. 0

    It appears that, in some cases, {{Collections.emptyMap()}} is being passed as the role qualifier instead of a null. The code below is from the KNS class {{DocumentAuthorizerBase}}. This appears to be causing a problem when attempting to cache the results of permission and role checks as you can see in the stack trace below: {code:title=DocumentAuthorizerBase.java} public final boolean canInitiate(String documentTypeName, Person user) { String nameSpaceCode = KRADConstants.KUALI_RICE_SYSTEM_NAMESPACE; Map<String, String> permissionDetails = new HashMap<String, String>(); permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME, documentTypeName); return getPermissionService().isAuthorizedByTemplate(user.getPrincipalId(), nameSpaceCode, KimConstants.PermissionTemplateNames.INITIATE_DOCUMENT, permissionDetails, Collections.<String, String>emptyMap()); } {code} {noformat} [junit] 2012-05-09 18:00:29,233 [main] u:/d:9212 WARN org.kuali.rice.kim.impl.role.RoleServiceImpl :: Not able to retrieve RoleTypeService from remote system for role Id: 92 [junit] java.lang.ClassCastException: java.util.Collections$EmptyMap cannot be cast to java.lang.Comparable [junit] at java.util.Collections.sort(Collections.java:121) [junit] at org.kuali.rice.core.api.cache.CacheKeyUtils.key(CacheKeyUtils.java:71) [junit] at $Proxy107.principalHasRole(Unknown Source) [junit] at org.kuali.kfs.fp.identity.CashReceiptInitiatorDerivedRoleTypeServiceImpl.hasRoleMembership(CashReceiptInitiatorDerivedRoleTypeServiceImpl.java:82) [junit] at org.kuali.kfs.fp.identity.CashReceiptInitiatorDerivedRoleTypeServiceImpl.principalMemberOfSysUsers(CashReceiptInitiatorDerivedRoleTypeServiceImpl.java:59) [junit] at org.kuali.kfs.fp.identity.CashReceiptInitiatorDerivedRoleTypeServiceImpl.hasDerivedRole(CashReceiptInitiatorDerivedRoleTypeServiceImpl.java:44) [junit] at org.kuali.rice.kim.impl.role.RoleServiceImpl.principalHasRole(RoleServiceImpl.java:1106) [junit] at org.kuali.rice.kim.impl.role.RoleServiceImpl.principalHasRole(RoleServiceImpl.java:498) [junit] at org.kuali.rice.kim.impl.permission.PermissionServiceImpl.isAuthorizedByTemplate(PermissionServiceImpl.java:172) [junit] at org.kuali.rice.kns.document.authorization.DocumentAuthorizerBase.canInitiate(DocumentAuthorizerBase.java:143) [junit] at org.kuali.rice.krad.service.impl.DocumentServiceImpl.getNewDocument(DocumentServiceImpl.java:506) [junit] at org.kuali.rice.krad.service.impl.DocumentServiceImpl.getNewDocument(DocumentServiceImpl.java:469) [junit] at org.kuali.kfs.sys.service.IsDebitTestUtils.getDocument(IsDebitTestUtils.java:110) [junit] at org.kuali.kfs.fp.document.validation.impl.CashReceiptDocumentRuleTest.testIsDebit_liability_zeroAmount(CashReceiptDocumentRuleTest.java:191) {noformat} (stripped reflection trace elements)

    Kuali JIRA | 5 years ago | Jonathan Keller
    java.lang.ClassCastException: java.util.Collections$EmptyMap cannot be cast to java.lang.Comparable

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.ClassCastException

      java.util.Collections$EmptyMap cannot be cast to java.util.TreeMap

      at com.thoughtworks.xstream.converters.collections.TreeMapConverter.marshal()
    2. XStream Core
      TreeMapConverter.marshal
      1. com.thoughtworks.xstream.converters.collections.TreeMapConverter.marshal(TreeMapConverter.java:50)
      1 frame
    3. Hudson
      CopyOnWriteMap$Tree$ConverterImpl.marshal
      1. hudson.util.CopyOnWriteMap$Tree$ConverterImpl.marshal(CopyOnWriteMap.java:221)
      1 frame
    4. XStream Core
      TreeMarshaller.convertAnother
      1. com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
      2. com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:78)
      3. com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:63)
      3 frames
    5. Hudson
      RobustReflectionConverter$2.visit
      1. hudson.util.RobustReflectionConverter.marshallField(RobustReflectionConverter.java:168)
      2. hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:156)
      3. hudson.util.RobustReflectionConverter$2.visit(RobustReflectionConverter.java:131)
      3 frames
    6. XStream Core
      PureJavaReflectionProvider.visitSerializableFields
      1. com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:130)
      1 frame
    7. Hudson
      RobustReflectionConverter.marshal
      1. hudson.util.RobustReflectionConverter.doMarshal(RobustReflectionConverter.java:116)
      2. hudson.util.RobustReflectionConverter.marshal(RobustReflectionConverter.java:89)
      2 frames
    8. XStream Core
      XStream.toXML
      1. com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
      2. com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:78)
      3. com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:63)
      4. com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:98)
      5. com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:38)
      6. com.thoughtworks.xstream.XStream.marshal(XStream.java:837)
      7. com.thoughtworks.xstream.XStream.marshal(XStream.java:826)
      8. com.thoughtworks.xstream.XStream.toXML(XStream.java:801)
      8 frames
    9. Hudson
      Executor.run
      1. hudson.XmlFile.write(XmlFile.java:161)
      2. hudson.model.Run.save(Run.java:1235)
      3. hudson.model.Run.run(Run.java:1162)
      4. hudson.model.Build.run(Build.java:74)
      5. hudson.model.ResourceController.execute(ResourceController.java:93)
      6. hudson.model.Executor.run(Executor.java:122)
      6 frames