From 7b2eb1a3ff124d92dbe8f9a874cdc015903495da Mon Sep 17 00:00:00 2001 From: Jay Anderson Date: Mon, 27 Jul 2015 12:08:29 -0700 Subject: [PATCH] Disallow null ports. Using null for the port ends up as a null pointer exception. --- src/main/java/redis/embedded/RedisServer.java | 6 +++--- .../java/redis/embedded/RedisServerBuilder.java | 14 ++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/java/redis/embedded/RedisServer.java b/src/main/java/redis/embedded/RedisServer.java index e2f7a3e4..10927f31 100644 --- a/src/main/java/redis/embedded/RedisServer.java +++ b/src/main/java/redis/embedded/RedisServer.java @@ -14,7 +14,7 @@ public RedisServer() throws IOException { this(DEFAULT_REDIS_PORT); } - public RedisServer(Integer port) throws IOException { + public RedisServer(int port) throws IOException { super(port); File executable = RedisExecProvider.defaultProvider().get(); this.args = Arrays.asList( @@ -23,7 +23,7 @@ public RedisServer(Integer port) throws IOException { ); } - public RedisServer(File executable, Integer port) { + public RedisServer(File executable, int port) { super(port); this.args = Arrays.asList( executable.getAbsolutePath(), @@ -31,7 +31,7 @@ public RedisServer(File executable, Integer port) { ); } - public RedisServer(RedisExecProvider redisExecProvider, Integer port) throws IOException { + public RedisServer(RedisExecProvider redisExecProvider, int port) throws IOException { super(port); this.args = Arrays.asList( redisExecProvider.get().getAbsolutePath(), diff --git a/src/main/java/redis/embedded/RedisServerBuilder.java b/src/main/java/redis/embedded/RedisServerBuilder.java index b050449c..affcbbd9 100644 --- a/src/main/java/redis/embedded/RedisServerBuilder.java +++ b/src/main/java/redis/embedded/RedisServerBuilder.java @@ -17,7 +17,7 @@ public class RedisServerBuilder { private File executable; private RedisExecProvider redisExecProvider = RedisExecProvider.defaultProvider(); - private Integer port = 6379; + private int port = 6379; private InetSocketAddress slaveOf; private String redisConf; @@ -27,13 +27,13 @@ public RedisServerBuilder redisExecProvider(RedisExecProvider redisExecProvider) this.redisExecProvider = redisExecProvider; return this; } - - public RedisServerBuilder port(Integer port) { + + public RedisServerBuilder port(int port) { this.port = port; return this; } - public RedisServerBuilder slaveOf(String hostname, Integer port) { + public RedisServerBuilder slaveOf(String hostname, int port) { this.slaveOf = new InetSocketAddress(hostname, port); return this; } @@ -113,10 +113,8 @@ private List buildCommandArgs() { args.add(redisConf); } - if (port != null) { - args.add("--port"); - args.add(Integer.toString(port)); - } + args.add("--port"); + args.add(Integer.toString(port)); if (slaveOf != null) { args.add("--slaveof");