Skip to content

Commit 9c15a07

Browse files
[BAEL-7802] - Static code analysis using Infer (#16645)
1 parent f69b2a5 commit 9c15a07

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed

static-analysis/infer/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<artifactId>infer</artifactId>
6+
7+
<parent>
8+
<groupId>com.baeldung</groupId>
9+
<artifactId>static-analysis</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
</parent>
12+
13+
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.infer;
2+
3+
public class DivideByZero {
4+
5+
public static void main(String[] args) {
6+
DivideByZero.divideByZero();
7+
}
8+
9+
private static void divideByZero() {
10+
int dividend = 5;
11+
int divisor = 0;
12+
int result = dividend / divisor;
13+
}
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung.infer;
2+
3+
public class NullPointerDereference {
4+
5+
public static void main(String[] args) {
6+
NullPointerDereference.nullPointerDereference();
7+
}
8+
9+
private static void nullPointerDereference() {
10+
String str = null;
11+
int length = str.length();
12+
}
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.infer;
2+
3+
import java.io.File;
4+
import java.io.FileOutputStream;
5+
import java.io.IOException;
6+
7+
public class ResourceLeak {
8+
9+
public static void main(String[] args) throws IOException {
10+
ResourceLeak.resourceLeak();
11+
}
12+
13+
private static void resourceLeak() throws IOException {
14+
FileOutputStream stream;
15+
try {
16+
File file = new File("randomName.txt");
17+
stream = new FileOutputStream(file);
18+
} catch (IOException e) {
19+
return;
20+
}
21+
stream.write(0);
22+
}
23+
}

static-analysis/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<module>pmd</module>
3535
<module>my-bugchecker-plugin</module>
3636
<module>error-prone-project</module>
37+
<module>infer</module>
3738
</modules>
3839

3940
<properties>

0 commit comments

Comments
 (0)