Mercurial > hg > release > thermostat-0.4
changeset 647:4323e78903af
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
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Mon, 01 Oct 2012 09:17:53 -0400 |
parents | 654fc29f96f2 |
children | ea7e9573f316 |
files | client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/LocaleResources.java client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/cli/FindObjectsCommand.java client/heapdumper/src/main/resources/com/redhat/thermostat/client/heap/strings.properties |
diffstat | 3 files changed, 16 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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,
--- 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<String> 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<String> results = heapDump.searchObjects(searchTerm, limit);
--- 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