Skip to content

Commit 3c47e0a

Browse files
committed
Handle null params in tx.run
1 parent d91525e commit 3c47e0a

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

driver/src/main/java/org/neo4j/driver/internal/InternalTransaction.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.neo4j.driver.v1.types.TypeSystem;
3636

3737
import static org.neo4j.driver.v1.Values.ofValue;
38+
import static org.neo4j.driver.v1.Values.value;
3839

3940
public class InternalTransaction implements Transaction
4041
{
@@ -142,14 +143,15 @@ public StatementResult run( String statementText )
142143
@Override
143144
public StatementResult run( String statementText, Map<String,Object> statementParameters )
144145
{
145-
return run( statementText, Values.value( statementParameters ) );
146+
Value params = statementParameters == null ? Values.EmptyMap : value(statementParameters);
147+
return run( statementText, params );
146148
}
147149

148150
@Override
149151
public StatementResult run( String statementTemplate, Record statementParameters )
150152
{
151-
// TODO: This conversion to map here is pointless, it gets converted right back
152-
return run( statementTemplate, statementParameters.asMap() );
153+
Value params = statementParameters == null ? Values.EmptyMap : value( statementParameters.asMap() );
154+
return run( statementTemplate, params );
153155
}
154156

155157
@Override

driver/src/test/java/org/neo4j/driver/v1/integration/TransactionIT.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import org.junit.Test;
2323
import org.junit.rules.ExpectedException;
2424

25+
import java.util.Map;
26+
27+
import org.neo4j.driver.v1.Record;
2528
import org.neo4j.driver.v1.StatementResult;
2629
import org.neo4j.driver.v1.Transaction;
2730
import org.neo4j.driver.v1.Value;
@@ -164,4 +167,48 @@ public void shouldHandleFailureAfterClosingTransaction()
164167
session.run("CREAT (n) RETURN n").consume();
165168
}
166169

170+
@SuppressWarnings( "ConstantConditions" )
171+
@Test
172+
public void shouldHandleNullRecordParameters() throws Throwable
173+
{
174+
// When
175+
try ( Transaction tx = session.beginTransaction() )
176+
{
177+
Record params = null;
178+
tx.run( "CREATE (n:FirstNode)", params );
179+
tx.success();
180+
}
181+
182+
// Then it wasn't the end of the world as we know it
183+
}
184+
185+
@SuppressWarnings( "ConstantConditions" )
186+
@Test
187+
public void shouldHandleNullValueParameters() throws Throwable
188+
{
189+
// When
190+
try ( Transaction tx = session.beginTransaction() )
191+
{
192+
Value params = null;
193+
tx.run( "CREATE (n:FirstNode)", params );
194+
tx.success();
195+
}
196+
197+
// Then it wasn't the end of the world as we know it
198+
}
199+
200+
@SuppressWarnings( "ConstantConditions" )
201+
@Test
202+
public void shouldHandleNullMapParameters() throws Throwable
203+
{
204+
// When
205+
try ( Transaction tx = session.beginTransaction() )
206+
{
207+
Map<String, Object> params = null;
208+
tx.run( "CREATE (n:FirstNode)", params );
209+
tx.success();
210+
}
211+
212+
// Then it wasn't the end of the world as we know it
213+
}
167214
}

0 commit comments

Comments
 (0)