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

Witek commented on ARIES-1554:
------------------------------

The consequence of using {{instanceof}} instead of {{getClass() == 
o.getClass()}} is that if someone extends FelixResourceAdapter (for whichever 
reason), then:

a) she needs to overwrite the equals method to properly return true for objects 
of superclass as the {{equals}} method needs to be symmetric (See 
[documentation|https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#equals%28java.lang.Object%29]
 and this [stackoverflow post|http://stackoverflow.com/a/32223])
b) the subtypes will always be equal (for maps, sets,...) as long as _type_, 
_symbolicName_ and _version_ are the same

On the other hand, if we use {{getClass() == o.getClass()}} then subtypes will 
always be different (not equal).

Is the approach that uses {{instanceof}} preferred here?


> FelixResourceAdapter returns true for resources of other types
> --------------------------------------------------------------
>
>                 Key: ARIES-1554
>                 URL: https://issues.apache.org/jira/browse/ARIES-1554
>             Project: Aries
>          Issue Type: Bug
>          Components: Subsystem
>         Environment: All
>            Reporter: Thomas Watson
>            Assignee: Thomas Watson
>
> The Resource implementation 
> org.apache.aries.subsystem.util.felix.FelixResourceAdapter does an equality 
> check based on the osgi.identity name, version, and type.  This typically is 
> not an issue but the contract for Resource.equals states the following:
> <javadoc>
> This Resource is equal to another Resource if both have the same content and 
> come from the same location. Location may be defined as the bundle location 
> if the resource is an installed bundle or the repository location if the 
> resource is in a repository.
> </javadoc>
> The assumption is that if the osgi.identity name, version and type are equal 
> then the resources have the "same content".  But the implementation does not 
> take into account the location.  This causes issues if resources are used as 
> keys in a Map and the Map will contain resources of different implementation 
> types.  This is done by the felix resolver implementation.  In some scenarios 
> the subsystems will return to the resolver resources from the OBR repository 
> and from the system repository (installed bundles) that have the same name, 
> version, type.  From the resolver's perspective these two resources must be 
> treated as distinctly different resources because they come from completely 
> different locations.  And the framework's Resource implementation of equals 
> does return false if checked against a FelixResourceAdapter, but the 
> FelixResourceAdapter equals method will return true if check against the 
> framework's Resource implementation.  This inconsistency in the equals 
> behavior reeks havoc for Map implementations.  Usually the issue is very 
> intermittent because of they way hash slots are determined based on 
> hashcodes, but in rare cases these two resources will be slotted the same and 
> collide with eachother depending on the Map implementation.
> At a minimum the FelixResourceAdapter should check that the other object is 
> an instance of FelixResourceAdapter to be able to return true.  This makes 
> the simple assumption that if the Resource is not of type 
> FelixResourceAdapter then there is no way the resource is at the same 
> location.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to