Skip to content

Commit 895583c

Browse files
committed
Fixed possible NPE in Font.hashCode()
1 parent 9a12df7 commit 895583c

File tree

1 file changed

+9
-17
lines changed
  • webfx-kit/webfx-kit-javafxgraphics-emul/src/main/java/javafx/scene/text

1 file changed

+9
-17
lines changed

webfx-kit/webfx-kit-javafxgraphics-emul/src/main/java/javafx/scene/text/Font.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -181,29 +181,21 @@ public static Font loadFont(String url, double size) {
181181
}
182182

183183
@Override
184-
public boolean equals(Object o) {
185-
if (this == o) return true;
186-
if (o == null || getClass() != o.getClass()) return false;
184+
public boolean equals(Object object) {
185+
if (object == null || getClass() != object.getClass()) return false;
187186

188-
Font font = (Font) o;
189-
190-
if (Double.compare(font.size, size) != 0) return false;
191-
if (!Objects.equals(name, font.name)) return false;
192-
if (!Objects.equals(family, font.family)) return false;
193-
if (weight != font.weight) return false;
194-
if (posture != font.posture) return false;
195-
return Objects.equals(url, font.url);
187+
Font font = (Font) object;
188+
return Double.compare(size, font.size) == 0 && Objects.equals(name, font.name) && Objects.equals(family, font.family) && weight == font.weight && posture == font.posture && Objects.equals(url, font.url);
196189
}
197190

198191
@Override
199192
public int hashCode() {
200-
int result;
201-
result = name != null ? name.hashCode() : 0;
202-
result = family != null ? 31 * result + family.hashCode() : 0;
203-
result = 31 * result + weight.hashCode();
204-
result = 31 * result + posture.hashCode();
193+
int result = Objects.hashCode(name);
194+
result = 31 * result + Objects.hashCode(family);
195+
result = 31 * result + Objects.hashCode(weight);
196+
result = 31 * result + Objects.hashCode(posture);
205197
result = 31 * result + Double.hashCode(size);
206-
result = 31 * result + (url != null ? url.hashCode() : 0);
198+
result = 31 * result + Objects.hashCode(url);
207199
return result;
208200
}
209201

0 commit comments

Comments
 (0)