IDEA-173861 Format string "%d%" is not flagged as invalid

This commit is contained in:
Sergey Prigogin
2017-06-06 09:06:46 +02:00
committed by Bas Leijdekkers
parent e4e4ab3c32
commit 3e4055d6ce
2 changed files with 6 additions and 6 deletions
@@ -248,7 +248,7 @@ class FormatDecode {
}
storeValidator(allowed, pos, parameters, argumentCount);
}
if (i < formatString.length() - 1) {
if (i < formatString.length()) {
checkText(formatString.substring(i));
}
@@ -7,16 +7,15 @@ import java.util.Formattable;
public class MalformedFormatString {
public void foo()
{
String.<warning descr="Too many arguments for format string (found: 1, expected: 0)">format</warning>("%", 3.0);
System.out.<warning descr="Too many arguments for format string (found: 1, expected: 0)">printf</warning>("%", 3.0);
public void foo() {
String.<warning descr="Too many arguments for format string (found: 1, expected: 0)">format</warning>("%%", 3.0);
System.out.<warning descr="Too many arguments for format string (found: 2, expected: 1)">printf</warning>("%s", 3.0, 2.0);
System.out.printf(<warning descr="Illegal format string specifier: unknown conversion in '%q'">"%q"</warning>, 3.0);
System.out.printf("%d", <warning descr="Argument type 'double' does not match the type of the format specifier '%d'">3.0</warning>);
System.out.printf(new Locale(""),"%d%s", <warning descr="Argument type 'double' does not match the type of the format specifier '%d'">3.0</warning>, "foo");
}
public static void main(String[] args) {
public static void main(String[] args) {
String local = "hmm";
String good = String.format("%s %s", 1, 2); // this is valid according to the inspector (correct)
@@ -60,6 +59,7 @@ public class MalformedFormatString {
void badStrings() {
// bad format specifier
String.format(<warning descr="Format string '\"%) %n\"' is malformed">"%) %n"</warning>);
String.format(<warning descr="Format string '\"%d%\"' is malformed">"%d%"</warning>, 1);
// flags on newline not allowed
String.format(<warning descr="Illegal format string specifier: flag '(' not allowed in '%(n'">"%(n"</warning>);