mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 08:18:29 +00:00
@NonNull now uses a slightly longer exception message.
This commit is contained in:
1 parent
198efc1b27
commit
a0b901c3c0
23 files changed
+52
-52
No files matched your search
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The Project Lombok Authors.
|
||||
* Copyright (C) 2014-2018 The Project Lombok Authors.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -26,7 +26,7 @@ package lombok.core.configuration;
|
||||
public enum NullCheckExceptionType {
|
||||
ILLEGAL_ARGUMENT_EXCEPTION {
|
||||
public String toExceptionMessage(String fieldName) {
|
||||
return fieldName + " is null";
|
||||
return fieldName + " is marked @NonNull but is null";
|
||||
}
|
||||
|
||||
@Override public String getExceptionType() {
|
||||
@@ -35,7 +35,7 @@ public enum NullCheckExceptionType {
|
||||
},
|
||||
NULL_POINTER_EXCEPTION {
|
||||
@Override public String toExceptionMessage(String fieldName) {
|
||||
return fieldName + " is marked as @NonNull but is null";
|
||||
return fieldName + " is marked @NonNull but is null";
|
||||
}
|
||||
|
||||
public String getExceptionType() {
|
||||
|
||||
@@ -26,16 +26,16 @@ class ConstructorsWithAccessorsNonNull {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public ConstructorsWithAccessorsNonNull(@lombok.NonNull final Integer plower, @lombok.NonNull final Integer upper, @lombok.NonNull final Integer huh, @lombok.NonNull final Integer _huh2) {
|
||||
if (plower == null) {
|
||||
throw new java.lang.NullPointerException("plower");
|
||||
throw new java.lang.NullPointerException("plower is marked @NonNull but is null");
|
||||
}
|
||||
if (upper == null) {
|
||||
throw new java.lang.NullPointerException("upper");
|
||||
throw new java.lang.NullPointerException("upper is marked @NonNull but is null");
|
||||
}
|
||||
if (huh == null) {
|
||||
throw new java.lang.NullPointerException("huh");
|
||||
throw new java.lang.NullPointerException("huh is marked @NonNull but is null");
|
||||
}
|
||||
if (_huh2 == null) {
|
||||
throw new java.lang.NullPointerException("_huh2");
|
||||
throw new java.lang.NullPointerException("_huh2 is marked @NonNull but is null");
|
||||
}
|
||||
this.plower = plower;
|
||||
this.pUpper = upper;
|
||||
|
||||
@@ -64,7 +64,7 @@ class DataOnLocalClass2 {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public InnerLocal(@lombok.NonNull final String name) {
|
||||
if (name == null) {
|
||||
throw new java.lang.NullPointerException("name");
|
||||
throw new java.lang.NullPointerException("name is marked @NonNull but is null");
|
||||
}
|
||||
this.name = name;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ class DataOnLocalClass2 {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public void setName(@lombok.NonNull final String name) {
|
||||
if (name == null) {
|
||||
throw new java.lang.NullPointerException("name");
|
||||
throw new java.lang.NullPointerException("name is marked @NonNull but is null");
|
||||
}
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@@ -2,22 +2,22 @@ class NonNullOnParameter extends Thread {
|
||||
NonNullOnParameter(@lombok.NonNull String arg) {
|
||||
this(arg, "");
|
||||
if (arg == null) {
|
||||
throw new java.lang.NullPointerException("arg");
|
||||
throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
|
||||
}
|
||||
}
|
||||
NonNullOnParameter(@lombok.NonNull String arg, @lombok.NonNull String arg2) {
|
||||
super(arg);
|
||||
if (arg2 == null) {
|
||||
throw new java.lang.NullPointerException("arg2");
|
||||
throw new java.lang.NullPointerException("arg2 is marked @NonNull but is null");
|
||||
}
|
||||
if (arg == null) throw new NullPointerException();
|
||||
}
|
||||
public void test2(@lombok.NonNull String arg, @lombok.NonNull String arg2, @lombok.NonNull String arg3) {
|
||||
if (arg == null) {
|
||||
throw new java.lang.NullPointerException("arg");
|
||||
throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
|
||||
}
|
||||
if (arg3 == null) {
|
||||
throw new java.lang.NullPointerException("arg3");
|
||||
throw new java.lang.NullPointerException("arg3 is marked @NonNull but is null");
|
||||
}
|
||||
if (arg2 == null) {
|
||||
throw new NullPointerException("arg2");
|
||||
@@ -26,21 +26,21 @@ class NonNullOnParameter extends Thread {
|
||||
}
|
||||
public void test3(@lombok.NonNull String arg) {
|
||||
if (arg == null) {
|
||||
throw new java.lang.NullPointerException("arg");
|
||||
throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
|
||||
}
|
||||
if (arg != null) throw new IllegalStateException();
|
||||
}
|
||||
public void test(@lombok.NonNull String stringArg, @lombok.NonNull String arg2, @lombok.NonNull int primitiveArg) {
|
||||
if (stringArg == null) {
|
||||
throw new java.lang.NullPointerException("stringArg");
|
||||
throw new java.lang.NullPointerException("stringArg is marked @NonNull but is null");
|
||||
}
|
||||
if (arg2 == null) {
|
||||
throw new java.lang.NullPointerException("arg2");
|
||||
throw new java.lang.NullPointerException("arg2 is marked @NonNull but is null");
|
||||
}
|
||||
}
|
||||
public void test(@lombok.NonNull String arg) {
|
||||
if (arg == null) {
|
||||
throw new java.lang.NullPointerException("arg");
|
||||
throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
|
||||
}
|
||||
System.out.println("Hey");
|
||||
if (arg == null) throw new NullPointerException();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
abstract class NonNullOnParameterAbstract {
|
||||
public void test(@lombok.NonNull String arg) {
|
||||
if (arg == null) {
|
||||
throw new java.lang.NullPointerException("arg");
|
||||
throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
|
||||
}
|
||||
System.out.println("Hey");
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ interface NonNullOnParameterOfDefaultMethod {
|
||||
void test(@lombok.NonNull String arg);
|
||||
default void test2(@lombok.NonNull String arg) {
|
||||
if (arg == null) {
|
||||
throw new java.lang.NullPointerException("arg");
|
||||
throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
|
||||
}
|
||||
System.out.println(arg);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class NonNullPlain {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public NonNullPlain(@lombok.NonNull final int i, @lombok.NonNull final String s) {
|
||||
if (s == null) {
|
||||
throw new java.lang.NullPointerException("s");
|
||||
throw new java.lang.NullPointerException("s is marked @NonNull but is null");
|
||||
}
|
||||
this.i = i;
|
||||
this.s = s;
|
||||
@@ -39,7 +39,7 @@ class NonNullPlain {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public void setS(@lombok.NonNull final String s) {
|
||||
if (s == null) {
|
||||
throw new java.lang.NullPointerException("s");
|
||||
throw new java.lang.NullPointerException("s is marked @NonNull but is null");
|
||||
}
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
@@ -3,14 +3,14 @@ public class NonNullWithAlternateException {
|
||||
private String test;
|
||||
public void testMethod(@lombok.NonNull String arg) {
|
||||
if (arg == null) {
|
||||
throw new java.lang.IllegalArgumentException("arg is null");
|
||||
throw new java.lang.IllegalArgumentException("arg is marked @NonNull but is null");
|
||||
}
|
||||
System.out.println(arg);
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public void setTest(@lombok.NonNull final String test) {
|
||||
if (test == null) {
|
||||
throw new java.lang.IllegalArgumentException("test is null");
|
||||
throw new java.lang.IllegalArgumentException("test is marked @NonNull but is null");
|
||||
}
|
||||
this.test = test;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ class NonNullWithSneakyThrows {
|
||||
void test(@lombok.NonNull String in) {
|
||||
try {
|
||||
if (in == null) {
|
||||
throw new java.lang.NullPointerException("in");
|
||||
throw new java.lang.NullPointerException("in is marked @NonNull but is null");
|
||||
}
|
||||
System.out.println(in);
|
||||
} catch (final java.lang.Throwable $ex) {
|
||||
|
||||
@@ -54,7 +54,7 @@ class SetterOnClass6 {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public void setNonNull(@lombok.NonNull final String nonNull) {
|
||||
if (nonNull == null) {
|
||||
throw new java.lang.NullPointerException("nonNull");
|
||||
throw new java.lang.NullPointerException("nonNull is marked @NonNull but is null");
|
||||
}
|
||||
this.nonNull = nonNull;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class WitherOnClass3 {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public WitherOnClass3 withNonNull(@lombok.NonNull final String nonNull) {
|
||||
if (nonNull == null) {
|
||||
throw new java.lang.NullPointerException("nonNull");
|
||||
throw new java.lang.NullPointerException("nonNull is marked @NonNull but is null");
|
||||
}
|
||||
return this.nonNull == nonNull ? this : new WitherOnClass3(this.couldBeNull, nonNull);
|
||||
}
|
||||
|
||||
@@ -20,19 +20,19 @@
|
||||
super();
|
||||
if ((plower == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("plower");
|
||||
throw new java.lang.NullPointerException("plower is marked @NonNull but is null");
|
||||
}
|
||||
if ((upper == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("upper");
|
||||
throw new java.lang.NullPointerException("upper is marked @NonNull but is null");
|
||||
}
|
||||
if ((huh == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("huh");
|
||||
throw new java.lang.NullPointerException("huh is marked @NonNull but is null");
|
||||
}
|
||||
if ((_huh2 == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("_huh2");
|
||||
throw new java.lang.NullPointerException("_huh2 is marked @NonNull but is null");
|
||||
}
|
||||
this.plower = plower;
|
||||
this.pUpper = upper;
|
||||
|
||||
@@ -64,7 +64,7 @@ class DataOnLocalClass2 {
|
||||
public @java.lang.SuppressWarnings("all") void setName(final @lombok.NonNull String name) {
|
||||
if ((name == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("name");
|
||||
throw new java.lang.NullPointerException("name is marked @NonNull but is null");
|
||||
}
|
||||
this.name = name;
|
||||
}
|
||||
@@ -99,7 +99,7 @@ class DataOnLocalClass2 {
|
||||
super();
|
||||
if ((name == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("name");
|
||||
throw new java.lang.NullPointerException("name is marked @NonNull but is null");
|
||||
}
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@@ -3,14 +3,14 @@ class NonNullOnParameter extends Thread {
|
||||
this(arg, "");
|
||||
if ((arg == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("arg");
|
||||
throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
|
||||
}
|
||||
}
|
||||
NonNullOnParameter(@lombok.NonNull String arg, @lombok.NonNull String arg2) {
|
||||
super(arg);
|
||||
if ((arg2 == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("arg2");
|
||||
throw new java.lang.NullPointerException("arg2 is marked @NonNull but is null");
|
||||
}
|
||||
if ((arg == null))
|
||||
throw new NullPointerException();
|
||||
@@ -18,11 +18,11 @@ class NonNullOnParameter extends Thread {
|
||||
public void test2(@lombok.NonNull String arg, @lombok.NonNull String arg2, @lombok.NonNull String arg3) {
|
||||
if ((arg == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("arg");
|
||||
throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
|
||||
}
|
||||
if ((arg3 == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("arg3");
|
||||
throw new java.lang.NullPointerException("arg3 is marked @NonNull but is null");
|
||||
}
|
||||
if ((arg2 == null))
|
||||
{
|
||||
@@ -34,7 +34,7 @@ class NonNullOnParameter extends Thread {
|
||||
public void test3(@lombok.NonNull String arg) {
|
||||
if ((arg == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("arg");
|
||||
throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
|
||||
}
|
||||
if ((arg != null))
|
||||
throw new IllegalStateException();
|
||||
@@ -42,17 +42,17 @@ class NonNullOnParameter extends Thread {
|
||||
public void test(@lombok.NonNull String stringArg, @lombok.NonNull String arg2, @lombok.NonNull int primitiveArg) {
|
||||
if ((stringArg == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("stringArg");
|
||||
throw new java.lang.NullPointerException("stringArg is marked @NonNull but is null");
|
||||
}
|
||||
if ((arg2 == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("arg2");
|
||||
throw new java.lang.NullPointerException("arg2 is marked @NonNull but is null");
|
||||
}
|
||||
}
|
||||
public void test(@lombok.NonNull String arg) {
|
||||
if ((arg == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("arg");
|
||||
throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
|
||||
}
|
||||
System.out.println("Hey");
|
||||
if ((arg == null))
|
||||
|
||||
@@ -5,7 +5,7 @@ abstract class NonNullOnParameterAbstract {
|
||||
public void test(@lombok.NonNull String arg) {
|
||||
if ((arg == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("arg");
|
||||
throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
|
||||
}
|
||||
System.out.println("Hey");
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ interface NonNullOnParameterOfDefaultMethod {
|
||||
default void test2(@lombok.NonNull String arg) {
|
||||
if ((arg == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("arg");
|
||||
throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
|
||||
}
|
||||
System.out.println(arg);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.lang.annotation.*;
|
||||
super();
|
||||
if ((s == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("s");
|
||||
throw new java.lang.NullPointerException("s is marked @NonNull but is null");
|
||||
}
|
||||
this.i = i;
|
||||
this.s = s;
|
||||
@@ -29,7 +29,7 @@ import java.lang.annotation.*;
|
||||
public @java.lang.SuppressWarnings("all") void setS(final @lombok.NonNull String s) {
|
||||
if ((s == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("s");
|
||||
throw new java.lang.NullPointerException("s is marked @NonNull but is null");
|
||||
}
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
@@ -6,14 +6,14 @@ public class NonNullWithAlternateException {
|
||||
public void testMethod(@lombok.NonNull String arg) {
|
||||
if ((arg == null))
|
||||
{
|
||||
throw new java.lang.IllegalArgumentException("arg is null");
|
||||
throw new java.lang.IllegalArgumentException("arg is marked @NonNull but is null");
|
||||
}
|
||||
System.out.println(arg);
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") void setTest(final @lombok.NonNull String test) {
|
||||
if ((test == null))
|
||||
{
|
||||
throw new java.lang.IllegalArgumentException("test is null");
|
||||
throw new java.lang.IllegalArgumentException("test is marked @NonNull but is null");
|
||||
}
|
||||
this.test = test;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ class NonNullWithSneakyThrows {
|
||||
{
|
||||
if ((in == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("in");
|
||||
throw new java.lang.NullPointerException("in is marked @NonNull but is null");
|
||||
}
|
||||
System.out.println(in);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
public @java.lang.SuppressWarnings("all") void setNonNull(final @lombok.NonNull String nonNull) {
|
||||
if ((nonNull == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("nonNull");
|
||||
throw new java.lang.NullPointerException("nonNull is marked @NonNull but is null");
|
||||
}
|
||||
this.nonNull = nonNull;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
public @java.lang.SuppressWarnings("all") WitherOnClass3 withNonNull(final @lombok.NonNull String nonNull) {
|
||||
if ((nonNull == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("nonNull");
|
||||
throw new java.lang.NullPointerException("nonNull is marked @NonNull but is null");
|
||||
}
|
||||
return ((this.nonNull == nonNull) ? this : new WitherOnClass3(this.couldBeNull, nonNull));
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
</p><p>
|
||||
Lombok has always treated any annotation named <code>@NonNull</code> on a field as a signal to generate a null-check if lombok generates an entire method or constructor for you, via for example <a href="/features/Data"><code>@Data</code></a>. Now, however, using lombok's own <code>@lombok.NonNull</code> on a parameter results in the insertion of just the null-check statement inside your own method or constructor.
|
||||
</p><p>
|
||||
The null-check looks like <code>if (param == null) throw new NullPointerException("param");</code> and will be inserted at the very top of your method. For constructors, the null-check will be inserted immediately following any explicit <code>this()</code> or <code>super()</code> calls.
|
||||
The null-check looks like <code>if (param == null) throw new NullPointerException("param is marked @NonNull but is null");</code> and will be inserted at the very top of your method. For constructors, the null-check will be inserted immediately following any explicit <code>this()</code> or <code>super()</code> calls.
|
||||
</p><p>
|
||||
If a null-check is already present at the top, no additional null-check will be generated.
|
||||
</p>
|
||||
@@ -23,7 +23,7 @@
|
||||
<dt>
|
||||
<code>lombok.nonNull.exceptionType</code> = [<code>NullPointerException</code> | <code>IllegalArgumentException</code>] (default: <code>NullPointerException</code>).
|
||||
</dt><dd>
|
||||
When lombok generates a null-check <code>if</code> statement, by default, a <code>java.lang.NullPointerException</code> will be thrown with the field name as the exception message. However, you can use <code>IllegalArgumentException</code> in this configuration key to have lombok throw that exception, with '<em>fieldName</em> is null' as exception message.
|
||||
When lombok generates a null-check <code>if</code> statement, by default, a <code>java.lang.NullPointerException</code> will be thrown with '<em>field name</em> is marked @NonNull but is null' as the exception message. However, you can use <code>IllegalArgumentException</code> in this configuration key to have lombok throw that exception with this message instead.
|
||||
</dd><dt>
|
||||
<code>lombok.nonNull.flagUsage</code> = [<code>warning</code> | <code>error</code>] (default: not set)
|
||||
</dt><dd>
|
||||
|
||||
@@ -6,7 +6,7 @@ public class NonNullExample extends Something {
|
||||
public NonNullExample(@NonNull Person person) {
|
||||
super("Hello");
|
||||
if (person == null) {
|
||||
throw new NullPointerException("person");
|
||||
throw new NullPointerException("person is marked @NonNull but is null");
|
||||
}
|
||||
this.name = person.getName();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user