bkoelman / ResharperCodeContractNullability

Reports diagnostics, helping you to annotate your source tree with (Item)NotNull / (Item)CanBeNull attributes.
https://www.jetbrains.com/resharper/help/Code_Analysis__Code_Annotations.html
Apache License 2.0
26 stars 4 forks source link

Incorrect missing attribute report (with broken build after applying codefix) #27

Closed bkoelman closed 8 years ago

bkoelman commented 8 years ago

In the process of determining where the (Item)CanBeNull/(Item)NotNull attributes are defined, their visibility is taken into account. Internal attributes are chosen only when the project asking for them is the same project. However, for better performance, the last-known location of these attributes is cached. The bug here is that when retrieving the locations from cache, visibility is not re-checked.

Repro steps:

  1. Create class library
  2. Add internal annotations (see below)
  3. Add a string property, wait for analyzer to report and apply code fix
  4. Add new Console application to the same solution (do not restart VS)
  5. Add project reference from class library to console application
  6. In the console application, add new class with string property.
  7. Wait for analyzer to report on the new string property (which it should not)
  8. Apply suggested code fix and observe broken build

Code for step 2:

internal class CanBeNullAttribute : Attribute { }
internal class NotNullAttribute : Attribute { }
internal class ItemNotNullAttribute : Attribute { }
internal class ItemCanBeNullAttribute : Attribute { }