From 09245046fddfa93e8ce16185a3cfbd72de7889c2 Mon Sep 17 00:00:00 2001 From: pmarguerite Date: Fri, 2 Feb 2007 17:39:51 +0000 Subject: [PATCH] Avoid creation of ClientHandle and UserHandle objects with null attributes. Otherwise, problem with null pointer exception. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@343 be28352e-c001-0410-b1a7-c7978e42abec --- .../client/simpleclient/SimpleClientFactory.java | 48 ++++++++++++++++++-- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/src/uk/ac/vamsas/client/simpleclient/SimpleClientFactory.java b/src/uk/ac/vamsas/client/simpleclient/SimpleClientFactory.java index d948f92..b4a74d3 100644 --- a/src/uk/ac/vamsas/client/simpleclient/SimpleClientFactory.java +++ b/src/uk/ac/vamsas/client/simpleclient/SimpleClientFactory.java @@ -205,12 +205,38 @@ public class SimpleClientFactory implements IClientFactory { if (userId == null) { //create a default userHandle - //with current OS user and hostname - userId = new UserHandle(System.getProperty("user.name", System.getProperty("USERNAME","Joe Doe")), - System.getProperty("host.name",System.getProperty("HOSTNAME", "Unknown") ));// clientName, clientVersion, sessionPath); + // userId = new UserHandle(System.getProperty("user.name", System.getProperty("USERNAME","Joe Doe")), + // System.getProperty("host.name",System.getProperty("HOSTNAME", "Unknown") ));// clientName, clientVersion, sessionPath); + userId = new UserHandle(null, null); + } - - + + //FullName and organisation should not be null (otherwise UserHandle equals method raises an java.lang.NullPointerException ) + //use current OS user and hostname, if null + if ( userId.getFullName() == null) + { + userId.setFullName(System.getProperty("user.name", System.getProperty("USERNAME","Joe Doe"))); + } + + if (userId.getOrganization() == null) + { + userId.setOrganization( System.getProperty("host.name",System.getProperty("HOSTNAME", "Unknown") )); + } + + if (clientHandle == null) + clientHandle = new ClientHandle("SimpleVamsasClientApp","0.1"); + else + { + if (clientHandle.getClientName() == null) + { + clientHandle.setClientName("SimpleVamsasClientApp"); + } + if (clientHandle.getVersion() == null) + { + clientHandle.setVersion("0.1"); + } + } + //create simple client client = new SimpleClient(userId, clientHandle, vamsasSession); vamsasSession.addClient(client); @@ -233,7 +259,19 @@ public class SimpleClientFactory implements IClientFactory { //create default clientHandle with "SimpleVamsasClientApp","0.1", if (clientHandle == null) clientHandle = new ClientHandle("SimpleVamsasClientApp","0.1"); + else + { + if (clientHandle.getClientName() == null) + { + clientHandle.setClientName("SimpleVamsasClientApp"); + } + + if (clientHandle.getVersion() == null) + { + clientHandle.setVersion("0.1"); + } + } //check if any available session(s) String[] availableSessions = this.getCurrentSessions(); if (availableSessions != null) -- 1.7.10.2