[
https://issues.apache.org/jira/browse/FELIX-4425?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13908781#comment-13908781
]
Nicolas Roduit edited comment on FELIX-4425 at 2/21/14 10:18 PM:
-----------------------------------------------------------------
The following fix works with Java 7 and Java 8:
diff --git
a/gogo/shell/src/main/java/org/apache/felix/gogo/options/Options.java
b/gogo/shell/src/main/java/org/apache/felix/gogo/options/Options.java
index e2fdba0..570b067 100644
--- a/gogo/shell/src/main/java/org/apache/felix/gogo/options/Options.java
+++ b/gogo/shell/src/main/java/org/apache/felix/gogo/options/Options.java
@@ -470,16 +470,15 @@
}
}
else {
- int i = 0;
- for (String c : arg.substring(1).split("")) {
- if (i++ == 0)
- continue;
+ for (int i = 1; i < arg.length(); i++) {
+ String c = String.valueOf(arg.charAt(i));
if (optName.containsKey(c)) {
String name = optName.get(c);
optSet.put(name, true);
if (optArg.containsKey(name)) {
- if (i < arg.length()) {
- addArg(name, arg.substring(i));
+ int k = i + 1;
+ if (k < arg.length()) {
+ addArg(name, arg.substring(k));
}
else {
needOpt = c;
was (Author: nroduit):
The following fix works with Java 7 and Java 8:
Replace
{code}
int i = 0;
for (String c : arg.substring(1).split("")) {
if (i++ == 0)
continue;
...
{code}
by
{code}
for (int i = 1; i < arg.length(); i++) {
String c = String.valueOf(arg.charAt(i));
...
{code}
> Short command in Gogo Shell not working with Java 8
> ----------------------------------------------------
>
> Key: FELIX-4425
> URL: https://issues.apache.org/jira/browse/FELIX-4425
> Project: Felix
> Issue Type: Bug
> Components: Gogo Command
> Environment: Java 8
> Reporter: Nicolas Roduit
>
> The bug comes from the different interpretation of String.split() method in
> line 474 of org.apache.felix.gogo.options.Options (in Gogo Shell).
> Here are the different results of the split method:
> String val = "-k".substring(1).split("");
> Java < 8:
> val[0]=""
> val[1]="k"
> Java 8:
> val[0]="k"
> A simple fix can be an iteration of the characters instead of using split().
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)