Skip to content

Commit 64d39dd

Browse files
committed
Framing a null element return null.
https://github.com/tinkerpop/frames/issues/58
1 parent 0e84d1c commit 64d39dd

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

CHANGELOG.textile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ h3. Version 2.4.0 (NOT OFFICIALLY RELEASED YET)
1515
</dependency>
1616
```
1717

18+
* Framing a null element returns null
1819
* Fixed NPE when enum property type set to null
1920
* Inheritance/Poymorphism support
2021
* Factory/Module support
2122
* Fix detection of parameterized return types
22-
* AdjacencyAnnotationHandler operates against the graph being framed rather than the base graph
23-
* FramedTransactionalGraph support
24-
* Support subclassing in FramedGraphFactory
23+
* @AdjacencyAnnotationHandler@ operates against the graph being framed rather than the base graph
24+
* @FramedTransactionalGraph@ support
25+
* Support subclassing in @FramedGraphFactory@
2526
==<hr/>==
2627

2728
h3. Version 2.3.2 (NOT OFFICIALLY RELEASED YET)

src/main/java/com/tinkerpop/frames/FramedGraph.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ public FramedGraph(final T baseGraph) {
8686
* perspective of the annotate interface
8787
*/
8888
public <F> F frame(final Vertex vertex, final Class<F> kind) {
89+
if(vertex == null) {
90+
return null;
91+
}
92+
8993
Collection<Class<?>> resolvedTypes = new HashSet<Class<?>>();
9094
resolvedTypes.add(VertexFrame.class);
9195
resolvedTypes.add(kind);
@@ -115,6 +119,11 @@ public <F> F frame(final Vertex vertex, final Class<F> kind) {
115119
*/
116120
public <F> F frame(final Edge edge, final Direction direction,
117121
final Class<F> kind) {
122+
123+
if(edge == null) {
124+
return null;
125+
}
126+
118127
Collection<Class<?>> resolvedTypes = new HashSet<Class<?>>();
119128
resolvedTypes.add(EdgeFrame.class);
120129
resolvedTypes.add(kind);

src/test/java/com/tinkerpop/frames/FramedGraphTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.lang.reflect.Method;
44
import java.util.HashSet;
55

6+
import junit.framework.Assert;
7+
68
import com.tinkerpop.blueprints.Direction;
79
import com.tinkerpop.blueprints.Edge;
810
import com.tinkerpop.blueprints.EdgeTestSuite;
@@ -97,6 +99,21 @@ public void testCreateFrame() {
9799

98100
}
99101

102+
public void testCreateFrameForNonexistantElements() {
103+
Graph graph = new TinkerGraph();
104+
FramedGraph<Graph> framedGraph = new FramedGraphFactory().create(graph);
105+
Person vertex = framedGraph.getVertex(-1, Person.class);
106+
Assert.assertNull(vertex);
107+
vertex = framedGraph.frame(null, Direction.IN, Person.class);
108+
Assert.assertNull(vertex);
109+
110+
Knows edge = framedGraph.getEdge(-1, Direction.IN, Knows.class);
111+
Assert.assertNull(edge);
112+
edge = framedGraph.frame(null, Direction.IN, Knows.class);
113+
Assert.assertNull(edge);
114+
115+
}
116+
100117

101118
public void testVertexTestSuite() throws Exception {
102119
this.stopWatch();

0 commit comments

Comments
 (0)