Skip to content

Commit ba7515a

Browse files
committed
fix: handle nullpointer
1 parent 9f7fa70 commit ba7515a

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

plugin/src/main/java/io/snyk/languageserver/protocolextension/messageObjects/PublishDiagnostics316Param.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,41 @@ public void setUri(String uri) {
2020
}
2121

2222
public Diagnostic316[] getDiagnostics() {
23-
return Arrays.copyOf(diagnostics, diagnostics.length);
23+
if (diagnostics == null) {
24+
return new Diagnostic316[0]; // Return an empty array if diagnostics is null
25+
}
26+
return Arrays.copyOf(diagnostics, diagnostics.length);
2427
}
2528

29+
2630
public void setDiagnostics(Diagnostic316... diagnostics) {
2731
this.diagnostics = diagnostics.clone();
2832
}
2933

3034
@Override
3135
public int hashCode() {
32-
final int prime = 31;
33-
int result = 1;
34-
result = prime * result + Arrays.hashCode(diagnostics);
35-
result = prime * result + Objects.hash(uri);
36-
return result;
36+
final int prime = 31;
37+
int result = 1;
38+
result = prime * result + (diagnostics == null ? 0 : Arrays.hashCode(diagnostics));
39+
result = prime * result + Objects.hash(uri);
40+
return result;
3741
}
3842

3943
@Override
4044
public boolean equals(Object obj) {
41-
if (this == obj)
42-
return true;
43-
if (obj == null)
44-
return false;
45-
if (getClass() != obj.getClass())
46-
return false;
47-
PublishDiagnostics316Param other = (PublishDiagnostics316Param) obj;
48-
return Arrays.equals(diagnostics, other.diagnostics) && Objects.equals(uri, other.uri);
45+
if (this == obj)
46+
return true;
47+
if (obj == null)
48+
return false;
49+
if (getClass() != obj.getClass())
50+
return false;
51+
PublishDiagnostics316Param other = (PublishDiagnostics316Param) obj;
52+
return (diagnostics == null ? other.diagnostics == null : Arrays.equals(diagnostics, other.diagnostics))
53+
&& Objects.equals(uri, other.uri);
4954
}
5055

5156
@Override
5257
public String toString() {
53-
return "PublishDiagnostic316Param [uri=" + uri + ", diagnostics=" + Arrays.toString(diagnostics) + "]";
58+
return "PublishDiagnostic316Param [uri=" + uri + ", diagnostics=" + (diagnostics == null ? "null" : Arrays.toString(diagnostics)) + "]";
5459
}
5560
}

0 commit comments

Comments
 (0)