Mercurial > hg > release > thermostat-1.2
changeset 1527:de5f72a3381a
Command Code Fixes
Made commands use requireNonNull
line wrap: on
line diff
--- a/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/impl/ServiceCommand.java Mon Oct 20 14:16:54 2014 -0400 +++ b/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/impl/ServiceCommand.java Tue Oct 21 14:02:57 2014 -0400 @@ -79,9 +79,7 @@ public void run(CommandContext ctx) throws CommandException { cmdCtx = ctx; ServiceReference launcherRef = context.getServiceReference(Launcher.class); - if (launcherRef == null) { - throw new CommandException(translator.localize(LocaleResources.LAUNCHER_UNAVAILABLE)); - } + requireNonNull(launcherRef, translator.localize(LocaleResources.LAUNCHER_UNAVAILABLE)); launcher = (Launcher) context.getService(launcherRef); String[] storageStartArgs = new String[] { "storage", "--start", "--permitLocalhostException"}; launcher.run(storageStartArgs, listeners, false);
--- a/client/cli/src/main/java/com/redhat/thermostat/client/cli/internal/CleanDataCommand.java Mon Oct 20 14:16:54 2014 -0400 +++ b/client/cli/src/main/java/com/redhat/thermostat/client/cli/internal/CleanDataCommand.java Tue Oct 21 14:02:57 2014 -0400 @@ -65,9 +65,7 @@ @Override public void run(CommandContext ctx) throws CommandException { ServiceReference storageServiceRef = bundleContext.getServiceReference(Storage.class); - if (storageServiceRef == null) { - throw new CommandException(translator.localize(LocaleResources.STORAGE_UNAVAILABLE)); - } + requireNonNull(storageServiceRef, translator.localize(LocaleResources.STORAGE_UNAVAILABLE)); Storage storage = (Storage) bundleContext.getService(storageServiceRef); try { @@ -88,9 +86,7 @@ public void removeDataForSpecifiedAgents(Storage storage, List <String> agentIdList, PrintStream output) throws CommandException { ServiceReference agentServiceRef = bundleContext.getServiceReference(AgentInfoDAO.class); - if (agentServiceRef == null) { - throw new CommandException(translator.localize(LocaleResources.AGENT_UNAVAILABLE)); - } + requireNonNull(agentServiceRef, translator.localize(LocaleResources.AGENT_UNAVAILABLE)); AgentInfoDAO agentInfoDAO = (AgentInfoDAO) bundleContext.getService(agentServiceRef); try { @@ -109,9 +105,7 @@ public void removeDataForAllAgents(Storage storage, PrintStream output) throws CommandException { ServiceReference agentServiceRef = bundleContext.getServiceReference(AgentInfoDAO.class); - if (agentServiceRef == null) { - throw new CommandException(translator.localize(LocaleResources.AGENT_UNAVAILABLE)); - } + requireNonNull(agentServiceRef, translator.localize(LocaleResources.AGENT_UNAVAILABLE)); AgentInfoDAO agentInfoDAO = (AgentInfoDAO) bundleContext.getService(agentServiceRef); try {
--- a/client/cli/src/main/java/com/redhat/thermostat/client/cli/internal/DisconnectCommand.java Mon Oct 20 14:16:54 2014 -0400 +++ b/client/cli/src/main/java/com/redhat/thermostat/client/cli/internal/DisconnectCommand.java Tue Oct 21 14:02:57 2014 -0400 @@ -64,10 +64,9 @@ @Override public void run(CommandContext ctx) throws CommandException { ServiceReference ref = context.getServiceReference(DbService.class.getName()); - if (ref == null) { - // not connected - throw new CommandException(translator.localize(LocaleResources.COMMAND_DISCONNECT_NOT_CONNECTED)); - } + + // if ref is null then we are not connected + requireNonNull(ref, translator.localize(LocaleResources.COMMAND_DISCONNECT_NOT_CONNECTED)); try { DbService service = (DbService) context.getService(ref);
--- a/client/cli/src/main/java/com/redhat/thermostat/client/cli/internal/ListAgentsCommand.java Mon Oct 20 14:16:54 2014 -0400 +++ b/client/cli/src/main/java/com/redhat/thermostat/client/cli/internal/ListAgentsCommand.java Tue Oct 21 14:02:57 2014 -0400 @@ -60,7 +60,7 @@ public void run(CommandContext ctx) throws CommandException { waitForServices(500l); - requireNotNull(agentInfoDAO, translator.localize(LocaleResources.AGENT_SERVICE_UNAVAILABLE)); + requireNonNull(agentInfoDAO, translator.localize(LocaleResources.AGENT_SERVICE_UNAVAILABLE)); listAgents(ctx.getConsole().getOutput(), agentInfoDAO.getAllAgentInformation()); }
--- a/client/cli/src/main/java/com/redhat/thermostat/client/cli/internal/ListVMsCommand.java Mon Oct 20 14:16:54 2014 -0400 +++ b/client/cli/src/main/java/com/redhat/thermostat/client/cli/internal/ListVMsCommand.java Tue Oct 21 14:02:57 2014 -0400 @@ -70,18 +70,16 @@ public void run(CommandContext ctx) throws CommandException { ServiceReference hostsDAORef = context.getServiceReference(HostInfoDAO.class.getName()); - if (hostsDAORef == null) { - throw new CommandException(translator.localize(LocaleResources.HOST_SERVICE_UNAVAILABLE)); - } + requireNonNull(hostsDAORef, translator.localize(LocaleResources.HOST_SERVICE_UNAVAILABLE)); HostInfoDAO hostsDAO = (HostInfoDAO) context.getService(hostsDAORef); + Collection<HostRef> hosts = hostsDAO.getHosts(); context.ungetService(hostsDAORef); ServiceReference vmsDAORef = context.getServiceReference(VmInfoDAO.class.getName()); - if (vmsDAORef == null) { - throw new CommandException(translator.localize(LocaleResources.VM_SERVICE_UNAVAILABLE)); - } + requireNonNull(vmsDAORef, translator.localize(LocaleResources.VM_SERVICE_UNAVAILABLE)); VmInfoDAO vmsDAO = (VmInfoDAO) context.getService(vmsDAORef); + VMListFormatter formatter = new VMListFormatter(); formatter.addHeader(); for (HostRef host : hosts) {
--- a/client/cli/src/main/java/com/redhat/thermostat/client/cli/internal/VMInfoCommand.java Mon Oct 20 14:16:54 2014 -0400 +++ b/client/cli/src/main/java/com/redhat/thermostat/client/cli/internal/VMInfoCommand.java Tue Oct 21 14:02:57 2014 -0400 @@ -76,9 +76,7 @@ @Override public void run(CommandContext ctx) throws CommandException { ServiceReference vmsDAORef = context.getServiceReference(VmInfoDAO.class.getName()); - if (vmsDAORef == null) { - throw new CommandException(translator.localize(LocaleResources.VM_SERVICE_UNAVAILABLE)); - } + requireNonNull(vmsDAORef, translator.localize(LocaleResources.VM_SERVICE_UNAVAILABLE)); VmInfoDAO vmsDAO = (VmInfoDAO) context.getService(vmsDAORef); HostVMArguments hostVMArgs = new HostVMArguments(ctx.getArguments(), true, false);
--- a/client/command/src/main/java/com/redhat/thermostat/client/command/cli/PingCommand.java Mon Oct 20 14:16:54 2014 -0400 +++ b/client/command/src/main/java/com/redhat/thermostat/client/command/cli/PingCommand.java Tue Oct 21 14:02:57 2014 -0400 @@ -125,9 +125,7 @@ } ServiceReference hostInfoDaoRef = context.getServiceReference(HostInfoDAO.class.getName()); - if (hostInfoDaoRef == null) { - throw new CommandException(translator.localize(LocaleResources.COMMAND_PING_NO_HOST_INFO_DAO)); - } + requireNonNull(hostInfoDaoRef, translator.localize(LocaleResources.COMMAND_PING_NO_HOST_INFO_DAO)); HostInfoDAO hostInfoDao = (HostInfoDAO) context.getService(hostInfoDaoRef); HostRef targetHostRef = getHostRef(hostInfoDao, agentId); context.ungetService(hostInfoDaoRef); @@ -137,9 +135,7 @@ return; } ServiceReference agentInfoDaoRef = context.getServiceReference(AgentInfoDAO.class.getName()); - if (agentInfoDaoRef == null) { - throw new CommandException(translator.localize(LocaleResources.COMMAND_PING_NO_AGENT_INFO_DAO)); - } + requireNonNull(agentInfoDaoRef, translator.localize(LocaleResources.COMMAND_PING_NO_AGENT_INFO_DAO)); AgentInfoDAO agentInfoDao = (AgentInfoDAO) context.getService(agentInfoDaoRef); String address = agentInfoDao.getAgentInformation(targetHostRef).getConfigListenAddress(); context.ungetService(agentInfoDaoRef); @@ -153,9 +149,7 @@ ping.addListener(new PongListener(out, responseBarrier, translator)); ServiceReference queueRef = context.getServiceReference(RequestQueue.class.getName()); - if (queueRef == null) { - throw new CommandException(translator.localize(LocaleResources.COMMAND_PING_NO_REQUEST_QUEUE)); - } + requireNonNull(queueRef, translator.localize(LocaleResources.COMMAND_PING_NO_REQUEST_QUEUE)); RequestQueue queue = (RequestQueue) context.getService(queueRef); out.println(translator.localize(LocaleResources.COMMAND_PING_QUEUING_REQUEST, target.toString()).getContents()); queue.putRequest(ping);
--- a/common/core/src/main/java/com/redhat/thermostat/common/cli/AbstractCommand.java Mon Oct 20 14:16:54 2014 -0400 +++ b/common/core/src/main/java/com/redhat/thermostat/common/cli/AbstractCommand.java Tue Oct 21 14:02:57 2014 -0400 @@ -54,7 +54,7 @@ return true; } - public void requireNotNull(Object obj, LocalizedString message) throws CommandException { + public void requireNonNull(Object obj, LocalizedString message) throws CommandException { if (obj == null) { throw new CommandException(message); }
--- a/dev/schema-info-command/command/src/main/java/com/redhat/thermostat/schemainfo/command/internal/SchemaInfoCommand.java Mon Oct 20 14:16:54 2014 -0400 +++ b/dev/schema-info-command/command/src/main/java/com/redhat/thermostat/schemainfo/command/internal/SchemaInfoCommand.java Tue Oct 21 14:02:57 2014 -0400 @@ -41,15 +41,15 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; -import com.redhat.thermostat.common.cli.Command; +import com.redhat.thermostat.common.cli.AbstractCommand; import com.redhat.thermostat.common.cli.CommandContext; import com.redhat.thermostat.common.cli.CommandException; +import com.redhat.thermostat.schemainfo.command.locale.LocaleResources; import com.redhat.thermostat.shared.locale.Translate; import com.redhat.thermostat.storage.dao.SchemaInfoDAO; -import com.redhat.thermostat.schemainfo.command.locale.LocaleResources; -import com.redhat.thermostat.storage.model.SchemaInformation;; +import com.redhat.thermostat.storage.model.SchemaInformation; -public class SchemaInfoCommand implements Command { +public class SchemaInfoCommand extends AbstractCommand { private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); public static final String commandName = "list-categories"; @@ -62,10 +62,8 @@ public void run(CommandContext ctx) throws CommandException { ServiceReference<?> schemaInfoDaoRef = context.getServiceReference(SchemaInfoDAO.class.getName()); - if (schemaInfoDaoRef == null) { - throw new CommandException(translator.localize(LocaleResources.SCHEMAINFO_SERVICE_UNAVAILABLE)); - } - + requireNonNull(schemaInfoDaoRef, translator.localize(LocaleResources.SCHEMAINFO_SERVICE_UNAVAILABLE)); + SchemaInfoDAO schemaInfoDao = (SchemaInfoDAO) context.getService(schemaInfoDaoRef); Collection<SchemaInformation> categoriesList = schemaInfoDao.getSchemaInfos(); @@ -78,10 +76,5 @@ } } } - - public boolean isStorageRequired() { - return true; - } - }
--- a/killvm/command/src/main/java/com/redhat/thermostat/killvm/command/KillVMCommand.java Mon Oct 20 14:16:54 2014 -0400 +++ b/killvm/command/src/main/java/com/redhat/thermostat/killvm/command/KillVMCommand.java Tue Oct 21 14:02:57 2014 -0400 @@ -73,10 +73,10 @@ @Override public void run(CommandContext ctx) throws CommandException { - requireNotNull(vmInfoDAO, translator.localize(LocaleResources.VM_SERVICE_UNAVAILABLE)); - requireNotNull(hostInfoDAO, translator.localize(LocaleResources.HOST_SERVICE_UNAVAILABLE)); - requireNotNull(agentInfoDAO, translator.localize(LocaleResources.AGENT_SERVICE_UNAVAILABLE)); - requireNotNull(requestQueue, translator.localize(LocaleResources.QUEUE_SERVICE_UNAVAILABLE)); + requireNonNull(vmInfoDAO, translator.localize(LocaleResources.VM_SERVICE_UNAVAILABLE)); + requireNonNull(hostInfoDAO, translator.localize(LocaleResources.HOST_SERVICE_UNAVAILABLE)); + requireNonNull(agentInfoDAO, translator.localize(LocaleResources.AGENT_SERVICE_UNAVAILABLE)); + requireNonNull(requestQueue, translator.localize(LocaleResources.QUEUE_SERVICE_UNAVAILABLE)); listener.setOut(ctx.getConsole().getOutput()); listener.setErr(ctx.getConsole().getError());
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/HelpCommand.java Mon Oct 20 14:16:54 2014 -0400 +++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/HelpCommand.java Tue Oct 21 14:02:57 2014 -0400 @@ -38,7 +38,6 @@ import java.io.PrintWriter; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator;
--- a/storage/mongo/src/main/java/com/redhat/thermostat/storage/mongodb/internal/AddUserCommand.java Mon Oct 20 14:16:54 2014 -0400 +++ b/storage/mongo/src/main/java/com/redhat/thermostat/storage/mongodb/internal/AddUserCommand.java Tue Oct 21 14:02:57 2014 -0400 @@ -94,9 +94,7 @@ public void run(CommandContext ctx) throws CommandException { // Check if mongodb stamp file exists. ServiceReference commonPathRef = context.getServiceReference(CommonPaths.class.getName()); - if (commonPathRef == null) { - throw new CommandException(t.localize(LocaleResources.COMMON_PATHS_SERVICE_UNAVAILABLE)); - } + requireNonNull(commonPathRef, t.localize(LocaleResources.COMMON_PATHS_SERVICE_UNAVAILABLE)); CommonPaths commonPath = (CommonPaths)context.getService(commonPathRef); File dataDir = commonPath.getUserPersistentDataDirectory(); // Since this is backing storage specific, it's most likely not a good @@ -132,9 +130,7 @@ reg.unregister(); ServiceReference storageRef = context.getServiceReference(Storage.class.getName()); - if (storageRef == null) { - throw new CommandException(t.localize(LocaleResources.STORAGE_SERVICE_UNAVAILABLE)); - } + requireNonNull(storageRef, t.localize(LocaleResources.STORAGE_SERVICE_UNAVAILABLE)); @SuppressWarnings("unchecked") // FIXME: Hack alarm. We use knowledge that via MongoStorageProvider we // have a MongoStorage instance wrapped in QueuedStorage. What's @@ -145,9 +141,7 @@ // impl specific. For now do this hack :-/ QueuedStorage storage = (QueuedStorage)context.getService(storageRef); MongoStorage mongoStorage = getDelegate(storage); - if (mongoStorage == null) { - throw new CommandException(t.localize(LocaleResources.MONGOSTORAGE_RETRIEVAL_FAILED)); - } + requireNonNull(mongoStorage, t.localize(LocaleResources.MONGOSTORAGE_RETRIEVAL_FAILED)); StorageAuthInfoGetter getter = null; try { LocalizedString userPrompt = new LocalizedString("Please enter the username you'd like to add to mongodb storage at " + dbUrl + ": ");
--- a/vm-heap-analysis/command/src/main/java/com/redhat/thermostat/vm/heap/analysis/command/internal/DumpHeapCommand.java Mon Oct 20 14:16:54 2014 -0400 +++ b/vm-heap-analysis/command/src/main/java/com/redhat/thermostat/vm/heap/analysis/command/internal/DumpHeapCommand.java Tue Oct 21 14:02:57 2014 -0400 @@ -92,21 +92,15 @@ }; ServiceReference vmInfoRef = context.getServiceReference(VmInfoDAO.class.getName()); - if (vmInfoRef == null) { - throw new CommandException(translator.localize(LocaleResources.VM_SERVICE_UNAVAILABLE)); - } + requireNonNull(vmInfoRef, translator.localize(LocaleResources.VM_SERVICE_UNAVAILABLE)); VmInfoDAO vmInfoDAO = (VmInfoDAO) context.getService(vmInfoRef); ServiceReference agentInfoRef = context.getServiceReference(AgentInfoDAO.class.getName()); - if (agentInfoRef == null) { - throw new CommandException(translator.localize(LocaleResources.AGENT_SERVICE_UNAVAILABLE)); - } + requireNonNull(agentInfoRef, translator.localize(LocaleResources.AGENT_SERVICE_UNAVAILABLE)); AgentInfoDAO agentInfoDAO = (AgentInfoDAO) context.getService(agentInfoRef); ServiceReference requestQueueRef = context.getServiceReference(RequestQueue.class.getName()); - if (requestQueueRef == null) { - throw new CommandException(translator.localize(LocaleResources.REQUEST_QUEUE_UNAVAILABLE)); - } + requireNonNull(requestQueueRef, translator.localize(LocaleResources.REQUEST_QUEUE_UNAVAILABLE)); RequestQueue queue = (RequestQueue) context.getService(requestQueueRef); implementation.execute(vmInfoDAO, agentInfoDAO, args.getVM(), queue, successHandler, errorHandler);
--- a/vm-heap-analysis/command/src/main/java/com/redhat/thermostat/vm/heap/analysis/command/internal/FindObjectsCommand.java Mon Oct 20 14:16:54 2014 -0400 +++ b/vm-heap-analysis/command/src/main/java/com/redhat/thermostat/vm/heap/analysis/command/internal/FindObjectsCommand.java Tue Oct 21 14:02:57 2014 -0400 @@ -77,9 +77,7 @@ @Override public void run(CommandContext ctx) throws CommandException { ServiceReference heapDAORef = context.getServiceReference(HeapDAO.class.getName()); - if (heapDAORef == null) { - throw new CommandException(translator.localize(LocaleResources.HEAP_SERVICE_UNAVAILABLE)); - } + requireNonNull(heapDAORef, translator.localize(LocaleResources.HEAP_SERVICE_UNAVAILABLE)); HeapDAO heapDAO = (HeapDAO) context.getService(heapDAORef); try { run(ctx, heapDAO);
--- a/vm-heap-analysis/command/src/main/java/com/redhat/thermostat/vm/heap/analysis/command/internal/FindRootCommand.java Mon Oct 20 14:16:54 2014 -0400 +++ b/vm-heap-analysis/command/src/main/java/com/redhat/thermostat/vm/heap/analysis/command/internal/FindRootCommand.java Tue Oct 21 14:02:57 2014 -0400 @@ -76,9 +76,7 @@ @Override public void run(CommandContext ctx) throws CommandException { ServiceReference heapDaoRef = context.getServiceReference(HeapDAO.class.getName()); - if (heapDaoRef == null) { - throw new CommandException(translator.localize(LocaleResources.HEAP_SERVICE_UNAVAILABLE)); - } + requireNonNull(heapDaoRef, translator.localize(LocaleResources.HEAP_SERVICE_UNAVAILABLE)); HeapDAO heapDao = (HeapDAO) context.getService(heapDaoRef); try {
--- a/vm-heap-analysis/command/src/main/java/com/redhat/thermostat/vm/heap/analysis/command/internal/ListHeapDumpsCommand.java Mon Oct 20 14:16:54 2014 -0400 +++ b/vm-heap-analysis/command/src/main/java/com/redhat/thermostat/vm/heap/analysis/command/internal/ListHeapDumpsCommand.java Tue Oct 21 14:02:57 2014 -0400 @@ -89,21 +89,15 @@ renderer.printLine(COLUMN_NAMES); ServiceReference hostDAORef = context.getServiceReference(HostInfoDAO.class.getName()); - if (hostDAORef == null) { - throw new CommandException(translator.localize(LocaleResources.HOST_SERVICE_UNAVAILABLE)); - } + requireNonNull(hostDAORef, translator.localize(LocaleResources.HOST_SERVICE_UNAVAILABLE)); HostInfoDAO hostDAO = (HostInfoDAO) context.getService(hostDAORef); ServiceReference vmDAORef = context.getServiceReference(VmInfoDAO.class.getName()); - if (vmDAORef == null) { - throw new CommandException(translator.localize(LocaleResources.VM_SERVICE_UNAVAILABLE)); - } + requireNonNull(vmDAORef, translator.localize(LocaleResources.VM_SERVICE_UNAVAILABLE)); VmInfoDAO vmDAO = (VmInfoDAO) context.getService(vmDAORef); ServiceReference heapDAORef = context.getServiceReference(HeapDAO.class.getName()); - if (heapDAORef == null) { - throw new CommandException(translator.localize(LocaleResources.HEAP_SERVICE_UNAVAILABLE)); - } + requireNonNull(heapDAORef, translator.localize(LocaleResources.HEAP_SERVICE_UNAVAILABLE)); HeapDAO heapDAO = (HeapDAO) context.getService(heapDAORef); Collection<HostRef> hosts = args.getHost() != null ? Arrays.asList(args.getHost()) : hostDAO.getHosts();
--- a/vm-heap-analysis/command/src/main/java/com/redhat/thermostat/vm/heap/analysis/command/internal/ObjectInfoCommand.java Mon Oct 20 14:16:54 2014 -0400 +++ b/vm-heap-analysis/command/src/main/java/com/redhat/thermostat/vm/heap/analysis/command/internal/ObjectInfoCommand.java Tue Oct 21 14:02:57 2014 -0400 @@ -75,9 +75,7 @@ @Override public void run(CommandContext ctx) throws CommandException { ServiceReference heapDaoRef = context.getServiceReference(HeapDAO.class.getName()); - if (heapDaoRef == null) { - throw new CommandException(translator.localize(LocaleResources.HEAP_SERVICE_UNAVAILABLE)); - } + requireNonNull(heapDaoRef, translator.localize(LocaleResources.HEAP_SERVICE_UNAVAILABLE)); HeapDAO heapDao = (HeapDAO) context.getService(heapDaoRef); try {
--- a/vm-heap-analysis/command/src/main/java/com/redhat/thermostat/vm/heap/analysis/command/internal/SaveHeapDumpToFileCommand.java Mon Oct 20 14:16:54 2014 -0400 +++ b/vm-heap-analysis/command/src/main/java/com/redhat/thermostat/vm/heap/analysis/command/internal/SaveHeapDumpToFileCommand.java Tue Oct 21 14:02:57 2014 -0400 @@ -52,6 +52,7 @@ import com.redhat.thermostat.common.cli.Arguments; import com.redhat.thermostat.common.cli.CommandContext; import com.redhat.thermostat.common.cli.CommandException; +import com.redhat.thermostat.common.cli.CommandLineArgumentParseException; import com.redhat.thermostat.common.utils.StreamUtils; import com.redhat.thermostat.shared.locale.Translate; import com.redhat.thermostat.vm.heap.analysis.command.locale.LocaleResources; @@ -80,9 +81,7 @@ @Override public void run(CommandContext ctx) throws CommandException { ServiceReference ref = context.getServiceReference(HeapDAO.class.getName()); - if (ref == null) { - throw new CommandException(translator.localize(LocaleResources.HEAP_SERVICE_UNAVAILABLE)); - } + requireNonNull(ref, translator.localize(LocaleResources.HEAP_SERVICE_UNAVAILABLE)); HeapDAO heapDAO = (HeapDAO) context.getService(ref); try { run(ctx, heapDAO); @@ -96,11 +95,11 @@ Arguments args = ctx.getArguments(); String heapId = args.getArgument(HEAP_ID_ARGUMENT); if (heapId == null) { - throw new CommandException(translator.localize(LocaleResources.HEAP_ID_REQUIRED)); + throw new CommandLineArgumentParseException(translator.localize(LocaleResources.HEAP_ID_REQUIRED)); } String filename = args.getArgument(FILE_NAME_ARGUMENT); if (filename == null) { - throw new CommandException(translator.localize(LocaleResources.FILE_REQUIRED)); + throw new CommandLineArgumentParseException(translator.localize(LocaleResources.FILE_REQUIRED)); } HeapInfo heapInfo = heapDAO.getHeapInfo(heapId);
--- a/vm-heap-analysis/command/src/main/java/com/redhat/thermostat/vm/heap/analysis/command/internal/ShowHeapHistogramCommand.java Mon Oct 20 14:16:54 2014 -0400 +++ b/vm-heap-analysis/command/src/main/java/com/redhat/thermostat/vm/heap/analysis/command/internal/ShowHeapHistogramCommand.java Tue Oct 21 14:02:57 2014 -0400 @@ -71,9 +71,7 @@ @Override public void run(CommandContext ctx) throws CommandException { ServiceReference ref = context.getServiceReference(HeapDAO.class.getName()); - if (ref == null) { - throw new CommandException(translator.localize(LocaleResources.HEAP_SERVICE_UNAVAILABLE)); - } + requireNonNull(ref, translator.localize(LocaleResources.HEAP_SERVICE_UNAVAILABLE)); HeapDAO heapDAO = (HeapDAO) context.getService(ref); try {