[jboss-jira] [JBoss JIRA] (LOGTOOL-109) Create @NotNull or @RequiresNonNull annotation to allow null checks with custom exception

James Perkins (JIRA) issues at jboss.org
Tue Jun 7 19:12:00 EDT 2016


James Perkins created LOGTOOL-109:
-------------------------------------

             Summary: Create @NotNull or @RequiresNonNull annotation to allow null checks with custom exception
                 Key: LOGTOOL-109
                 URL: https://issues.jboss.org/browse/LOGTOOL-109
             Project: Log Tool
          Issue Type: Feature Request
            Reporter: James Perkins


Use an {{@NotNull}} or {{@RequiresNonNull}} annotation on a method to generate a {{null}} check and throw, by default, an {{IllegalArgumentException}} if null. Also clean the stack trace.

{code:java|title=Example Interface}
@Message(id = 123, value = "Name cannot be null")
@NotNull(IllegalArgumentException.class)
void requireNotNull(String name);
{code}

{code:java|title=Example Generated Code}
@Override
public void requireNotNull(final String name) {
    if (name == null) {
        final IllegalArgumentException result = new IllegalArgumentException(String.format(invalidUser$str(), name));
        final StackTraceElement[] st = result.getStackTrace();
        result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
    }
}
{code}

The {{@Param}} annotation could be used along with {{@Pos}} for formatting possibly.



--
This message was sent by Atlassian JIRA
(v6.4.11#64026)


More information about the jboss-jira mailing list