You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Tommaso Teofili (JIRA)" <ji...@apache.org> on 2013/10/01 13:55:23 UTC

[jira] [Commented] (SLING-3140) ClassCastException while serializing byte[] in Sling Job with JCR Resource Resolver

    [ https://issues.apache.org/jira/browse/SLING-3140?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13782847#comment-13782847 ] 

Tommaso Teofili commented on SLING-3140:
----------------------------------------

I've implemented a possible fix at:
https://github.com/tteofili/sling/compare/apache:trunk...sling-3140.patch
 by catching such failures and using commons-lang's ArrayUtils#toObject method to explicitly convert primitive types arrays.


> 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:
> 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
>   }
> }



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