Skip to content

Commit f3d7a9d

Browse files
committed
move nullaway article
1 parent af27b7f commit f3d7a9d

6 files changed

Lines changed: 123 additions & 60 deletions

File tree

libraries-3/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m
1414
- [Introduction to cache2k](https://www.baeldung.com/java-cache2k)
1515
- [Introduction to the jcabi-aspects AOP Annotations Library](https://www.baeldung.com/java-jcabi-aspects)
1616
- [Introduction to Takes](https://www.baeldung.com/java-takes)
17+
- [Using NullAway to Avoid NullPointerExceptions](https://www.baeldung.com/java-nullaway)
18+

libraries-3/pom.xml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,23 @@
9494
<artifactId>velocity-engine-core</artifactId>
9595
<version>${velocity-engine-core.version}</version>
9696
</dependency>
97+
<dependency>
98+
<groupId>com.uber.nullaway</groupId>
99+
<artifactId>nullaway</artifactId>
100+
<version>0.3.0</version>
101+
</dependency>
102+
<dependency>
103+
<groupId>org.codehaus.plexus</groupId>
104+
<artifactId>plexus-compiler-javac-errorprone</artifactId>
105+
<version>2.8</version>
106+
</dependency>
107+
<!-- override plexus-compiler-javac-errorprone's dependency on
108+
Error Prone with the latest version -->
109+
<dependency>
110+
<groupId>com.google.errorprone</groupId>
111+
<artifactId>error_prone_core</artifactId>
112+
<version>2.1.3</version>
113+
</dependency>
97114
</dependencies>
98115

99116
<repositories>
@@ -130,6 +147,45 @@
130147
</dependency>
131148
</dependencies>
132149
</plugin>
150+
<plugin>
151+
<groupId>org.apache.maven.plugins</groupId>
152+
<artifactId>maven-compiler-plugin</artifactId>
153+
<version>3.5</version>
154+
<configuration>
155+
<compilerId>javac-with-errorprone</compilerId>
156+
<forceJavacCompilerUse>true</forceJavacCompilerUse>
157+
<source>1.8</source>
158+
<target>1.8</target>
159+
<showWarnings>true</showWarnings>
160+
<annotationProcessorPaths>
161+
<path>
162+
<groupId>com.uber.nullaway</groupId>
163+
<artifactId>nullaway</artifactId>
164+
<version>0.3.0</version>
165+
</path>
166+
</annotationProcessorPaths>
167+
<compilerArgs>
168+
<!-- NullAway will warn by default, uncomment the next line to make the build fail -->
169+
<!-- <arg>-Xep:NullAway:ERROR</arg> -->
170+
<arg>-XepExcludedPaths:(.*)/test/.*|(.*)/jcabi/.*</arg>
171+
<arg>-XepOpt:NullAway:AnnotatedPackages=com.baeldung.nullaway</arg>
172+
</compilerArgs>
173+
</configuration>
174+
<dependencies>
175+
<dependency>
176+
<groupId>org.codehaus.plexus</groupId>
177+
<artifactId>plexus-compiler-javac-errorprone</artifactId>
178+
<version>2.8</version>
179+
</dependency>
180+
<!-- override plexus-compiler-javac-errorprone's dependency on
181+
Error Prone with the latest version -->
182+
<dependency>
183+
<groupId>com.google.errorprone</groupId>
184+
<artifactId>error_prone_core</artifactId>
185+
<version>2.3.4</version>
186+
</dependency>
187+
</dependencies>
188+
</plugin>
133189
</plugins>
134190
<resources>
135191
<resource>

libraries/src/main/java/com/baeldung/nullaway/NullAwayExample.java renamed to libraries-3/src/main/java/com/baeldung/nullaway/NullAwayExample.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.baeldung.nullaway;
22

3-
import com.baeldung.distinct.Person;
4-
53
public class NullAwayExample {
64

75
/*
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.baeldung.nullaway;
2+
3+
public class Person {
4+
int age;
5+
String name;
6+
String email;
7+
8+
public Person(int age, String name, String email) {
9+
super();
10+
this.age = age;
11+
this.name = name;
12+
this.email = email;
13+
}
14+
15+
public int getAge() {
16+
return age;
17+
}
18+
19+
public String getName() {
20+
return name;
21+
}
22+
23+
public String getEmail() {
24+
return email;
25+
}
26+
27+
@Override
28+
public String toString() {
29+
StringBuilder builder = new StringBuilder();
30+
builder.append("Person [age=");
31+
builder.append(age);
32+
builder.append(", name=");
33+
builder.append(name);
34+
builder.append(", email=");
35+
builder.append(email);
36+
builder.append("]");
37+
return builder.toString();
38+
}
39+
40+
@Override
41+
public int hashCode() {
42+
final int prime = 31;
43+
int result = 1;
44+
result = prime * result + ((email == null) ? 0 : email.hashCode());
45+
return result;
46+
}
47+
48+
@Override
49+
public boolean equals(Object obj) {
50+
if (this == obj)
51+
return true;
52+
if (obj == null)
53+
return false;
54+
if (getClass() != obj.getClass())
55+
return false;
56+
Person other = (Person) obj;
57+
if (email == null) {
58+
if (other.email != null)
59+
return false;
60+
} else if (!email.equals(other.email))
61+
return false;
62+
return true;
63+
}
64+
65+
}

libraries/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,4 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m
4545
- [Implementing a FTP-Client in Java](https://www.baeldung.com/java-ftp-client)
4646
- [Introduction to Functional Java](https://www.baeldung.com/java-functional-library)
4747
- [A Guide to the Reflections Library](https://www.baeldung.com/reflections-library)
48-
- [Using NullAway to Avoid NullPointerExceptions](https://www.baeldung.com/java-nullaway)
4948
- More articles [[next -->]](/libraries-2)

libraries/pom.xml

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -435,23 +435,6 @@
435435
<artifactId>reflections</artifactId>
436436
<version>${reflections.version}</version>
437437
</dependency>
438-
<dependency>
439-
<groupId>com.uber.nullaway</groupId>
440-
<artifactId>nullaway</artifactId>
441-
<version>0.3.0</version>
442-
</dependency>
443-
<dependency>
444-
<groupId>org.codehaus.plexus</groupId>
445-
<artifactId>plexus-compiler-javac-errorprone</artifactId>
446-
<version>2.8</version>
447-
</dependency>
448-
<!-- override plexus-compiler-javac-errorprone's dependency on
449-
Error Prone with the latest version -->
450-
<dependency>
451-
<groupId>com.google.errorprone</groupId>
452-
<artifactId>error_prone_core</artifactId>
453-
<version>2.1.3</version>
454-
</dependency>
455438
</dependencies>
456439

457440
<repositories>
@@ -569,46 +552,6 @@
569552
</executions>
570553
</plugin>
571554

572-
<plugin>
573-
<groupId>org.apache.maven.plugins</groupId>
574-
<artifactId>maven-compiler-plugin</artifactId>
575-
<version>3.5</version>
576-
<configuration>
577-
<compilerId>javac-with-errorprone</compilerId>
578-
<forceJavacCompilerUse>true</forceJavacCompilerUse>
579-
<source>1.8</source>
580-
<target>1.8</target>
581-
<showWarnings>true</showWarnings>
582-
<annotationProcessorPaths>
583-
<path>
584-
<groupId>com.uber.nullaway</groupId>
585-
<artifactId>nullaway</artifactId>
586-
<version>0.3.0</version>
587-
</path>
588-
</annotationProcessorPaths>
589-
<compilerArgs>
590-
<!-- NullAway will warn by default, uncomment the next line to make the build fail -->
591-
<!-- <arg>-Xep:NullAway:ERROR</arg> -->
592-
<arg>-XepExcludedPaths:(.*)/test/.*|(.*)/streamex/.*</arg>
593-
<arg>-XepOpt:NullAway:AnnotatedPackages=com.baeldung.nullaway</arg>
594-
</compilerArgs>
595-
</configuration>
596-
<dependencies>
597-
<dependency>
598-
<groupId>org.codehaus.plexus</groupId>
599-
<artifactId>plexus-compiler-javac-errorprone</artifactId>
600-
<version>2.8</version>
601-
</dependency>
602-
<!-- override plexus-compiler-javac-errorprone's dependency on
603-
Error Prone with the latest version -->
604-
<dependency>
605-
<groupId>com.google.errorprone</groupId>
606-
<artifactId>error_prone_core</artifactId>
607-
<version>2.1.3</version>
608-
</dependency>
609-
</dependencies>
610-
</plugin>
611-
612555
</plugins>
613556
</build>
614557

0 commit comments

Comments
 (0)