Use VirtualFile.equals

IDEA 14 EAP is just around the corner. Good news is that it's going to use an optimized virtual file system implementation allowing for a more efficient memory usage, which should improve the way large projects are dealt with. There’s a downside as well: the contract will be broken that a single VirtualFile instance is preserved throughout the IDE session. Instead, there might be several lightweight VF instances corresponding to the same file. Don’t worry about the user data: it will be shared. But if your code compares VF objects using ==, or puts them into sets/maps with identity hashing strategy, it’s likely to be broken. So please correct such places.

IDEA master branch (138.* builds) is ready for this change and contains “Use VirtualFile.equals” inspection that allows to easily find == (and !=) usages in Java code. The inspection is also backported to 135.* builds and will appear in the next 13.1 EAP. If your plugin is in another JVM language and uses reference equality, please find such patterns yourselves. Good news is that most “other” languages already call “equals” where “==” is written. But look for identity strategies nevertheless: TObjectHashingStrategy, ContainerUtil#identityStrategy, IdentityHashMap and their callees.

Of course if you switch to “equals” and non-identity hashing strategies in builds for IDEA 12/13 as well, nothing bad will happen.

Sorry for the inconvenience.

Please sign in to leave a comment.