User defined preconditions support

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarQube Version 4.0.0.2929

  • what are you trying to achieve
    To enable user defined preconditions and functionality of a wrapped methods around standard methods of the Java language.

An Example of what we want to achieve:

FILE 1:

import java.util.Objects;

public class NonNullWrapper {

    // Wrapper around requireNonNull
    public static <T> T requireNonNullWrapper(T obj) {
        // Call the original requireNonNull method
        return Objects.requireNonNull(obj, "Object cannot be null!");
    }
}

FILE 2:

public class Main {

    public static void main(String[] args) {
        String testString = "Hello";

        // This should pass analysis
        System.out.println(NonNullWrapper.requireNonNullWrapper(testString));
    }
}
  • What have you tried so far to achieve this
    We found a similar ticket opened regarding this, mentioned here:
    [SONARJAVA-4026] - Jira
    Will be there any updates regarding progress of this in the near future?

Many Thanks for your continuous support!

Hi,

You can keep an eye on that ticket to know when there are changes. That said, this isn’t in our current priorities list, so I don’t expect movement any time soon.

 
:frowning:
Ann