You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by "Alex Craddock (Jira)" <ji...@apache.org> on 2021/08/02 17:18:00 UTC

[jira] [Updated] (TAP5-2687) Streamable Resource doesn't implement equals/hashCode

     [ https://issues.apache.org/jira/browse/TAP5-2687?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alex Craddock updated TAP5-2687:
--------------------------------
    Description: 
We use AssetChecksumGeneratorImpl to cache the file assets. I have found an issue where two seemingly identical resources are storing two copies of the same item in the cache.

 

I believe this is down to having two different StreamableResources which are equal based on the fields but when you try to use .hashMap on them they are not seen as equal (which I believe ConcurrentHashMap.get uses equals)

 
{code:java}
// code placeholder
package com.pubfactory.hk.web.services;

import org.apache.tapestry5.http.ContentType;
import org.apache.tapestry5.internal.services.assets.StreamableResourceImpl;
import org.apache.tapestry5.services.assets.CompressionStatus;

public class Test {

public static void main(String [] args) {


    StreamableResourceImpl streamableResource = new StreamableResourceImpl("description", new ContentType("application/json"),  CompressionStatus.COMPRESSABLE,123456l,
            null, null, null);
    StreamableResourceImpl streamableResource2 = new StreamableResourceImpl("description", new ContentType("application/json"),  CompressionStatus.COMPRESSABLE,123456l,
            null, null, null);

    System.out.print(streamableResource.hashCode() == streamableResource2.hashCode());
}
}
{code}
I wrote a test, which produces false when I would expect it to be true.

 

This is causing a memory leak on our sites. I monitored the AssetChecksumGeneratorImpl cache and it has gone from 1G in size to over 2G due to duplicate objects in the cache.

  was:
We use AssetChecksumGeneratorImpl to cache the file assets. I have found an issue where two seemingly identical resources are storing two copies of the same item in the cache.

 

I believe this is down to having two different StreamableResources which are equal based on the fields but when you try to use .equals on them they are not seen as equal (which I believe ConcurrentHashMap.get uses equals)

 
{code:java}
// code placeholder
package com.pubfactory.hk.web.services;

import org.apache.tapestry5.http.ContentType;
import org.apache.tapestry5.internal.services.assets.StreamableResourceImpl;
import org.apache.tapestry5.services.assets.CompressionStatus;

public class Test {

public static void main(String [] args) {


    StreamableResourceImpl streamableResource = new StreamableResourceImpl("description", new ContentType("application/json"),  CompressionStatus.COMPRESSABLE,123456l,
            null, null, null);
    StreamableResourceImpl streamableResource2 = new StreamableResourceImpl("description", new ContentType("application/json"),  CompressionStatus.COMPRESSABLE,123456l,
            null, null, null);

    System.out.print(streamableResource.hashCode() == streamableResource2.hashCode());
}
}
{code}
I wrote a test, which produces false when I would expect it to be true.

 

This is causing a memory leak on our sites. I monitored the AssetChecksumGeneratorImpl cache and it has gone from 1G in size to over 2G due to duplicate objects in the cache.


> Streamable Resource doesn't implement equals/hashCode
> -----------------------------------------------------
>
>                 Key: TAP5-2687
>                 URL: https://issues.apache.org/jira/browse/TAP5-2687
>             Project: Tapestry 5
>          Issue Type: Bug
>            Reporter: Alex Craddock
>            Priority: Critical
>
> We use AssetChecksumGeneratorImpl to cache the file assets. I have found an issue where two seemingly identical resources are storing two copies of the same item in the cache.
>  
> I believe this is down to having two different StreamableResources which are equal based on the fields but when you try to use .hashMap on them they are not seen as equal (which I believe ConcurrentHashMap.get uses equals)
>  
> {code:java}
> // code placeholder
> package com.pubfactory.hk.web.services;
> import org.apache.tapestry5.http.ContentType;
> import org.apache.tapestry5.internal.services.assets.StreamableResourceImpl;
> import org.apache.tapestry5.services.assets.CompressionStatus;
> public class Test {
> public static void main(String [] args) {
>     StreamableResourceImpl streamableResource = new StreamableResourceImpl("description", new ContentType("application/json"),  CompressionStatus.COMPRESSABLE,123456l,
>             null, null, null);
>     StreamableResourceImpl streamableResource2 = new StreamableResourceImpl("description", new ContentType("application/json"),  CompressionStatus.COMPRESSABLE,123456l,
>             null, null, null);
>     System.out.print(streamableResource.hashCode() == streamableResource2.hashCode());
> }
> }
> {code}
> I wrote a test, which produces false when I would expect it to be true.
>  
> This is causing a memory leak on our sites. I monitored the AssetChecksumGeneratorImpl cache and it has gone from 1G in size to over 2G due to duplicate objects in the cache.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)