[java:S1168] Rule seems to check simple name only


when declaring a function that has for example org.eclipse.draw2d.geometry.Vector as return type and returns null an issue is raised that an empty collection should be returned instead. This is impossible because this class is no java.util.Collection.

public class EmptyCollection {

  public Vector func(boolean selector) {
    if (selector) {
      return null;
          // ^^^^
          // Return an empty collection instead
    } else {
      return new Vector(1.0, 2.0);

It can be argued, that org.eclipse.draw2d.geometry.Vector.NULL could be used. However, in this case the message is misleading.


  • SonarQube 8.9 LTS
  • SonarLint 5.9

Hi Oliver,

Thank you for the report. This is indeed a false positive and I’ve created a ticket to fix it.

I’d say that in most situations that would be a bad change as one would assume that returning null is supposed to express something different than a vector whose components are zero.

This certainly isn’t the intention of the rule, the rule just wrongly assumed it was dealing with a collection.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.