New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recognize OpenDaylight's Immutable interface contract #1697
Comments
Aside from recognizing annotations, also treat any class that implements an interface named Immutable as an immutable class. Fixes spotbugs#1697. Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
Aside from recognizing annotations, also treat any class that implements an interface named Immutable as an immutable class. Fixes spotbugs#1697. Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
OpenDaylight has a type-safe marker interface which acts as API contract specification of effective immutability. Recognize this contract as equivalent to an inherited @immutable annotation. Fixes spotbugs#1697. Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
OpenDaylight has a type-safe marker interface which acts as API contract specification of effective immutability. Recognize this contract as equivalent to an inherited @immutable annotation. Fixes spotbugs#1697. Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
OpenDaylight has a type-safe marker interface which acts as API contract specification of effective immutability. Recognize this contract as equivalent to an inherited @immutable annotation. Fixes spotbugs#1697. Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
OpenDaylight has a type-safe marker interface which acts as API contract specification of effective immutability. Recognize this contract as equivalent to an inherited @immutable annotation. Fixes spotbugs#1697. Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
OpenDaylight has a type-safe marker interface which acts as API contract specification of effective immutability. Recognize this contract as equivalent to an inherited @immutable annotation. Fixes spotbugs#1697. Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
OpenDaylight has a type-safe marker interface which acts as API contract specification of effective immutability. Recognize this contract as equivalent to an inherited @immutable annotation. Fixes spotbugs#1697. Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
The problem with non-sealed interfaces is that their implementation can be anything, including something that bears public final class NotImmutableMapBuilder<K extends Immutable, V extends Immutable> implements ImmutableMapBuilder<K, V> {
private final java.util.Map<K, V> reallyVeryImmutableMapButNot = new java.util.HashMap<>();
@Override
public ImmutableMapBuilder<K, V> put(K key, V value) {
reallyVeryImmutableMapButNot.put(key, value);
return this;
}
// Really really very helpful, informative and heuristic-friendly name!
public V xxGroslynicateFooRqwz(K key) {
return reallyVeryImmutableMapButNot.get(key);
}
} With this, SpotBugs would see the interface and say "oh, so this is an immutable interface, fine then, I will mark all of its use as safe with regards of immutability". But then, some other module far from the place where the interface is defined, somewhere very far, far away down the road of a large multi-module application's build script, features that implementation. To be worse, every non- |
Agreed, I am specifically looking to understand OpenDaylight's contract in the context of determining mutability of classes on the class path, not in the project being analyzed. I believe we need to make that distinction, as otherwise SpotBugs would have to analyze the entire world in each run. In the specific example you listed, though, SpotBugs would only understand, for example, that So this issue is really about trusting an explicit contract rather than trying to outsmart it through some heuristic. We already trust annotations, so I do not quite see how this is worse :) |
OpenDaylight has a type-safe marker interface which acts as API contract specification of effective immutability. Recognize this contract as equivalent to an inherited @immutable annotation. Fixes spotbugs#1697. Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
During migration to spotbugs-4.4.1 in OpenDaylight we are noticing a number of new EI_EXPOSE_REP and MS_EXPOSE_REP warnings.
A large number of these are reported against types which are known to be immutable as part of their interface contract. This contract is not driven by annotations, but rather by implementing two dedicated interfaces,
Mutable and Immutable. These cannot be implemented simultaneously and can therefore be used to specify API expectations, such as (made up)
as well as runtime decisions without going to
java.lang.reflect
:Since
findbugs.util.MutableClasses
also reacts to any annotation named Immutable being attached to a class, it would be beneficial if it would also recognize/Immutable;
being extended or implemented in a type's hierarchy.The text was updated successfully, but these errors were encountered: