# HG changeset patch # User Omair Majid # Date 1349097473 14400 # Node ID 4323e78903afd0180537e67e3252577ac118158d # Parent 654fc29f96f24f352ecdaee12dfad6066393c11c find-objects should not throw IOOBE on missing search term 'find-objects' can throw a IndexOutOfBoundsException if no search term is provided on the command line. Make it print out a message to the user instead of crashing when that happens. Reviewed-by: jerboaa Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-September/003485.html diff -r 654fc29f96f2 -r 4323e78903af client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/LocaleResources.java --- a/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/LocaleResources.java Fri Sep 28 11:35:11 2012 -0400 +++ b/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/LocaleResources.java Mon Oct 01 09:17:53 2012 -0400 @@ -51,6 +51,7 @@ INVALID_LIMIT, HEAP_ID_NOT_FOUND, HEAP_ID_REQUIRED, + SEARCH_TERM_REQUIRED, ARGUMENT_HEAP_ID_DESCRIPTION, ARGUMENT_OBJECT_ID_DESCRIPTION, diff -r 654fc29f96f2 -r 4323e78903af client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/cli/FindObjectsCommand.java --- a/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/cli/FindObjectsCommand.java Fri Sep 28 11:35:11 2012 -0400 +++ b/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/cli/FindObjectsCommand.java Mon Oct 01 09:17:53 2012 -0400 @@ -38,6 +38,7 @@ import java.util.Arrays; import java.util.Collection; +import java.util.List; import com.redhat.thermostat.client.heap.LocaleResources; import com.redhat.thermostat.client.heap.Translate; @@ -77,7 +78,18 @@ ctx.getConsole().getOutput().println(Translate.localize(LocaleResources.HEAP_ID_NOT_FOUND, heapId)); return; } - String searchTerm = ctx.getArguments().getNonOptionArguments().get(0); + + List terms = ctx.getArguments().getNonOptionArguments(); + if (terms.size() == 0) { + ctx.getConsole().getOutput().println(Translate.localize(LocaleResources.SEARCH_TERM_REQUIRED)); + return; + } + String searchTerm = terms.get(0); + if (searchTerm.trim().length() == 0) { + ctx.getConsole().getOutput().println(Translate.localize(LocaleResources.SEARCH_TERM_REQUIRED)); + return; + } + String limitArg = ctx.getArguments().getArgument(LIMIT_ARG); int limit = parseLimit(limitArg); Collection results = heapDump.searchObjects(searchTerm, limit); diff -r 654fc29f96f2 -r 4323e78903af client/heapdumper/src/main/resources/com/redhat/thermostat/client/heap/strings.properties --- a/client/heapdumper/src/main/resources/com/redhat/thermostat/client/heap/strings.properties Fri Sep 28 11:35:11 2012 -0400 +++ b/client/heapdumper/src/main/resources/com/redhat/thermostat/client/heap/strings.properties Mon Oct 01 09:17:53 2012 -0400 @@ -11,6 +11,8 @@ INVALID_LIMIT = Invalid limit {0} HEAP_ID_NOT_FOUND = Heap ID not found: {0} HEAP_ID_REQUIRED = Heap ID required +SEARCH_TERM_REQUIRED = A search term is required + ARGUMENT_HEAP_ID_DESCRIPTION = the ID of the heapdump to analyze ARGUMENT_OBJECT_ID_DESCRIPTION = the ID of the object to query