From db03fca6c98ada8ea38c9322e92961151faa052c Mon Sep 17 00:00:00 2001 From: Matej Lukes <456316@mail.muni.cz> Date: Thu, 17 Oct 2019 13:12:22 +0200 Subject: [PATCH] null check added --- .../main/cz/fidentis/analyst/mesh/core/MeshComponent.java | 2 +- .../main/cz/fidentis/analyst/mesh/core/MeshComposite.java | 2 +- .../src/main/cz/fidentis/analyst/mesh/core/MeshEdge.java | 2 ++ .../src/main/cz/fidentis/analyst/mesh/core/MeshFacet.java | 6 ++++++ .../src/main/cz/fidentis/analyst/mesh/core/MeshPoint.java | 3 +++ 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/MeshModel/src/main/cz/fidentis/analyst/mesh/core/MeshComponent.java b/MeshModel/src/main/cz/fidentis/analyst/mesh/core/MeshComponent.java index 72608803..acbea11f 100644 --- a/MeshModel/src/main/cz/fidentis/analyst/mesh/core/MeshComponent.java +++ b/MeshModel/src/main/cz/fidentis/analyst/mesh/core/MeshComponent.java @@ -22,7 +22,7 @@ public abstract class MeshComponent { * @return true if newParent was successfully added, false otherwise */ public boolean addParent(MeshComponent newParent){ - if (parents.contains(newParent)) + if (newParent == null || parents.contains(newParent)) return false; parents.add(newParent); return true; diff --git a/MeshModel/src/main/cz/fidentis/analyst/mesh/core/MeshComposite.java b/MeshModel/src/main/cz/fidentis/analyst/mesh/core/MeshComposite.java index faf5270d..e4d1c57e 100644 --- a/MeshModel/src/main/cz/fidentis/analyst/mesh/core/MeshComposite.java +++ b/MeshModel/src/main/cz/fidentis/analyst/mesh/core/MeshComposite.java @@ -19,7 +19,7 @@ public class MeshComposite extends MeshComponent { */ @Override public boolean addChild(MeshComponent newChild) { - if (children.contains(newChild)) + if (newChild == null || children.contains(newChild)) return false; children.add(newChild); diff --git a/MeshModel/src/main/cz/fidentis/analyst/mesh/core/MeshEdge.java b/MeshModel/src/main/cz/fidentis/analyst/mesh/core/MeshEdge.java index bb95f224..f9a4fd2b 100644 --- a/MeshModel/src/main/cz/fidentis/analyst/mesh/core/MeshEdge.java +++ b/MeshModel/src/main/cz/fidentis/analyst/mesh/core/MeshEdge.java @@ -6,6 +6,8 @@ public class MeshEdge extends MeshComposite { public MeshEdge(MeshPoint point1, MeshPoint point2){ super(); + if (point1 == null || point2 == null) + throw new NullPointerException("point1 and point2 cannot be null"); super.addChild(point1); super.addChild(point2); } diff --git a/MeshModel/src/main/cz/fidentis/analyst/mesh/core/MeshFacet.java b/MeshModel/src/main/cz/fidentis/analyst/mesh/core/MeshFacet.java index db51d2d2..5afa5c8c 100644 --- a/MeshModel/src/main/cz/fidentis/analyst/mesh/core/MeshFacet.java +++ b/MeshModel/src/main/cz/fidentis/analyst/mesh/core/MeshFacet.java @@ -16,6 +16,9 @@ public class MeshFacet extends MeshComposite { * @return point from pointPool if it is in pointPool, null otherwise */ public MeshPoint getPoint(MeshPoint point) { + if (point == null) + return null; + MeshPoint result = pointPool.get(point); if (result == null) { pointPool.put(point, point); @@ -30,6 +33,9 @@ public class MeshFacet extends MeshComposite { * @return edge from edgePool if it is in edgePool, null otherwise */ public MeshEdge getEdge(MeshEdge edge) { + if (edge == null) + return null; + MeshEdge result = edgePool.get(edge); if (result == null) { edgePool.put(edge, edge); diff --git a/MeshModel/src/main/cz/fidentis/analyst/mesh/core/MeshPoint.java b/MeshModel/src/main/cz/fidentis/analyst/mesh/core/MeshPoint.java index 25d04b87..e066417b 100644 --- a/MeshModel/src/main/cz/fidentis/analyst/mesh/core/MeshPoint.java +++ b/MeshModel/src/main/cz/fidentis/analyst/mesh/core/MeshPoint.java @@ -7,6 +7,9 @@ public class MeshPoint extends MeshLeaf { private final Vector3d position, normal, texCoord; public MeshPoint(Vector3d position, Vector3d normal , Vector3d texCoord) { + if (position == null || normal == null || texCoord == null) + throw new NullPointerException("position, normal and texCoord cannot be null"); + this.position = position; this.normal = normal; this.texCoord = texCoord; -- GitLab