Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-3140

ClassCastException while serializing byte[] in Sling Job with JCR Resource Resolver

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • JCR Resource 2.2.8
    • JCR Resource 2.3.0
    • JCR
    • None

    Description

      When trying to serialize a byte[] in Sling Job properties Map I noticed that an error occurs when using the JCR Resource Resolver caused by a ClassCastException in JcrPropertyMapCacheEntry since it tries to cast a byte to Object. This therefore doesn't happen when serializing Byte[].
      This also happens when trying to serialize long/int/...[] due to the same cast.
      Here's the stacktrace:
      could not add an item to the queue java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object;
      at org.apache.sling.jcr.resource.internal.helper.JcrPropertyMapCacheEntry.<init>(JcrPropertyMapCacheEntry.java:94)
      at org.apache.sling.jcr.resource.internal.JcrModifiableValueMap.put(JcrModifiableValueMap.java:630)
      at org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProvider.create(JcrResourceProvider.java:453)
      at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.create(ResourceResolverImpl.java:1076)
      at org.apache.sling.api.resource.ResourceUtil.getOrCreateResource(ResourceUtil.java:578)
      at org.apache.sling.event.impl.support.ResourceHelper.getOrCreateResource(ResourceHelper.java:221)
      at org.apache.sling.event.impl.jobs.JobManagerImpl.writeJob(JobManagerImpl.java:1323)
      at org.apache.sling.event.impl.jobs.JobManagerImpl.addJobInteral(JobManagerImpl.java:1242)
      at org.apache.sling.event.impl.jobs.JobManagerImpl.addJob(JobManagerImpl.java:794)

      Here's the code snippet that triggers the error:
      Map<String, Object> properties = new HashMap<String, Object>();
      properties.put("BIN","a string".getBytes());
      Job job = jobManager.addJob("name", "id", properties);

      See testcase below to reproduce the problem on the JCR Resource Resolver:
      package org.apache.sling.jcr.resource.internal.helper;
      import org.junit.Test;
      public class JcrPropertyMapCacheEntryTest {
      @Test
      public void testByteArray() throws Exception

      { Byte[] ba = new Byte[0]; new JcrPropertyMapCacheEntry(ba, null); // ok byte[] ba2 = new byte[0]; new JcrPropertyMapCacheEntry(ba2, null); // fail }

      @Test
      public void testLongArray() throws Exception

      { Long[] ba = new Long[0]; new JcrPropertyMapCacheEntry(ba, null); // ok long[] ba2 = new long[0]; new JcrPropertyMapCacheEntry(ba2, null); // fail }

      }

      Attachments

        Activity

          People

            cziegeler Carsten Ziegeler
            teofili Tommaso Teofili
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: