sling-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tommaso Teofili (JIRA)" <j...@apache.org>
Subject [jira] [Created] (SLING-3140) ClassCastException while serializing byte[] in Sling Job with JCR Resource Resolver
Date Tue, 01 Oct 2013 06:49:29 GMT
Tommaso Teofili created SLING-3140:
--------------------------------------

             Summary: ClassCastException while serializing byte[] in Sling Job with JCR Resource
Resolver
                 Key: SLING-3140
                 URL: https://issues.apache.org/jira/browse/SLING-3140
             Project: Sling
          Issue Type: Bug
          Components: JCR
    Affects Versions: JCR Resource 2.2.8
            Reporter: Tommaso Teofili


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:
{code}
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)
{code}

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

See testcase below to reproduce the problem on the JCR Resource Resolver:
{code}
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
  }

}

{code}



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Mime
View raw message