[infinispan-issues] [JBoss JIRA] (ISPN-4067) Infinispan cannot put inner classes to write-behind cache
Adrian Nistor (JIRA)
issues at jboss.org
Mon Mar 3 05:20:48 EST 2014
[ https://issues.jboss.org/browse/ISPN-4067?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12949282#comment-12949282 ]
Adrian Nistor commented on ISPN-4067:
-------------------------------------
[~stanislav.ivanov] Since that's a non-static inner class it would need the 'outer this' reference when being unserialized. That's why it cannot work and has nothing to do with Infinispan. Similar questions are already answered here: http://stackoverflow.com/questions/7144912/why-is-a-serializable-inner-class-not-serializable
Making the inner class static should avoid the problem.
> Infinispan cannot put inner classes to write-behind cache
> ---------------------------------------------------------
>
> Key: ISPN-4067
> URL: https://issues.jboss.org/browse/ISPN-4067
> Project: Infinispan
> Issue Type: Bug
> Components: Marshalling
> Affects Versions: 6.0.0.Final
> Environment: JDK 1.7_45
> Reporter: Stanislav Ivanov
> Assignee: Dan Berindei
> Priority: Minor
>
> Infinispan throws NotSerializableException when trying to put inner class to write-behind cache.
> Here is the example:
> {code:title=class which I want to store in cache (actually, it's inside the other class)|borderStyle=solid}
> final class PojoCoder implements Serializable {
> private static final long serialVersionUID = -6238699065180988597L;
> private String name_;
> private String favouriteLanguage_;
> PojoCoder(String name, String favouriteLanguage) {
> name_ = name;
> favouriteLanguage_ = favouriteLanguage;
> }
> @Override
> public String toString() {
> return name_ + " loves " + favouriteLanguage_;
> }
> public String getFavouriteLanguage() {
> return favouriteLanguage_;
> }
> public String getName() {
> return name_;
> }
> }
> {code}
> {code:title=cache config|borderStyle=solid}
> final EmbeddedCacheManager cacheManager = new DefaultCacheManager();
> cacheManager.defineConfiguration(CACHE_NAME,
> new ConfigurationBuilder()
> .eviction()
> .maxEntries(2)
> .persistence()
> .passivation(false)
> .addSingleFileStore()
> .location(tmpStoragePath)
> .maxEntries(6)
> .build());
> {code}
> {code:title=code that fails|borderStyle=solid}
> final Cache<String, PojoCoder> testCache = cacheManager.getCache(CACHE_NAME);
> testCache.put("alex", new PojoCoder("django-lover alex", "Python")); //NotSerializableException on this line
> {code}
> Actually, stack trace tells something about problem with *this* reference.
> Unfortunatelly, I don't have time to investigate deeper this issue - inner class was created just for test, normally I would store typical outer classes.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the infinispan-issues
mailing list