Skip to content

Commit

Permalink
SONARJAVA-1369 Fix out of bounds when refering previous parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
benzonico committed Nov 23, 2015
1 parent 90a7b9f commit 2659b9d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ private void verifyParameters(MethodInvocationTree mit, List<ExpressionTree> arg
return;
}
param = param.substring(param.indexOf("$") + 1);
} else if (!param.startsWith("<")) {
} else if (param.startsWith("<")) {
//refers to previous argument
argIndex = Math.max(0, argIndex - 1);
}else {
index++;
}
ExpressionTree argExpressionTree = args.get(argIndex);
Expand Down
1 change: 1 addition & 0 deletions java-checks/src/test/files/checks/PrintfCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ void foo(Calendar c){

String.format("Dude's Birthday: %1$tm %<te,%<tY", c); // Compliant
String.format("Dude's Birthday: %1$tm %1$te,%1$tY", c); // Compliant
String.format("log/protocol_%tY_%<tm_%<td_%<tH_%<tM_%<tS.zip", new java.util.Date());
}
}

0 comments on commit 2659b9d

Please sign in to comment.