ATLAS-1912: fix for defects reported by Coverity scan

Signed-off-by: Madhan Neethiraj <madhan@apache.org>
diff --git a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
index 73dd33a..e8afed1 100644
--- a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
+++ b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
@@ -100,6 +100,7 @@
     INSTANCE_NOT_FOUND(404, "ATLAS-404-00-00B", "Given instance is invalid/not found: {0}"),
     RELATIONSHIP_GUID_NOT_FOUND(404, "ATLAS-404-00-00C", "Given relationship guid {0} is invalid/not found"),
     RELATIONSHIP_CRUD_INVALID_PARAMS(404, "ATLAS-404-00-00D", "Invalid relationship creation/updation parameters passed : {0}"),
+    RELATIONSHIPDEF_END_TYPE_NAME_NOT_FOUND(404, "ATLAS-404-00-00E", "RelationshipDef {0} endDef typename {0} cannot be found"),
     // All data conflict errors go here
     TYPE_ALREADY_EXISTS(409, "ATLAS-409-00-001", "Given type {0} already exists"),
     TYPE_HAS_REFERENCES(409, "ATLAS-409-00-002", "Given type {0} has references"),
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipDefStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipDefStoreV1.java
index bd7416e..ddf0af9 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipDefStoreV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipDefStoreV1.java
@@ -78,15 +78,23 @@
 
         updateVertexPreCreate(relationshipDef, (AtlasRelationshipType) type, relationshipDefVertex);
 
-        final AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1();
-        final String type1 = endDef1.getType();
-        final AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2();
-        final String type2 = endDef2.getType();
-        final String name1 = endDef1.getName();
-        final String name2 = endDef2.getName();
-        AtlasVertex end1TypeVertex = typeDefStore.findTypeVertexByName(type1);
+        final AtlasRelationshipEndDef endDef1        = relationshipDef.getEndDef1();
+        final AtlasRelationshipEndDef endDef2        = relationshipDef.getEndDef2();
+        final String                  type1          = endDef1.getType();
+        final String                  type2          = endDef2.getType();
+        final String                  name1          = endDef1.getName();
+        final String                  name2          = endDef2.getName();
+        final AtlasVertex             end1TypeVertex = typeDefStore.findTypeVertexByName(type1);
+        final AtlasVertex             end2TypeVertex = typeDefStore.findTypeVertexByName(type2);
 
-        AtlasVertex end2TypeVertex = typeDefStore.findTypeVertexByName(type2);
+        if (end1TypeVertex == null) {
+            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END_TYPE_NAME_NOT_FOUND, relationshipDef.getName(), type1);
+        }
+
+        if (end2TypeVertex == null) {
+            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END_TYPE_NAME_NOT_FOUND, relationshipDef.getName(), type2);
+        }
+
         // create an edge between the relationshipDef and each of the entityDef vertices.
         AtlasEdge edge1 = typeDefStore.getOrCreateEdge(relationshipDefVertex, end1TypeVertex, AtlasGraphUtilsV1.RELATIONSHIPTYPE_EDGE_LABEL);