diff options
author | Tor Norbye <tnorbye@google.com> | 2012-02-03 12:41:45 -0800 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2012-02-03 12:41:45 -0800 |
commit | 3af46df0c16ea6cec198b95ded6d865edd9c1a08 (patch) | |
tree | 736ab5de27b296364c0b47901164a3bf9efcce62 /lint | |
parent | eac6d9257ecb99f9a0149e5e803cb01ceb752551 (diff) | |
download | sdk-3af46df0c16ea6cec198b95ded6d865edd9c1a08.zip sdk-3af46df0c16ea6cec198b95ded6d865edd9c1a08.tar.gz sdk-3af46df0c16ea6cec198b95ded6d865edd9c1a08.tar.bz2 |
Disable String.format construction check
Change-Id: I2b0b118c2f4c3e64fb4c2e68ae594bb5e18a5938
Diffstat (limited to 'lint')
3 files changed, 26 insertions, 8 deletions
diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/StringFormatDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/StringFormatDetector.java index 975b6a3..2ab3f57 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/StringFormatDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/StringFormatDetector.java @@ -51,7 +51,6 @@ import java.util.EnumSet; import java.util.Formatter; import java.util.HashMap; import java.util.HashSet; -import java.util.IllegalFormatException; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -413,23 +412,28 @@ public class StringFormatDetector extends ResourceXmlDetector implements Detecto // Check that the format string is valid by actually attempting to instantiate // it. We only do this if we haven't already complained about this string // for other reasons. + /* Check disabled for now: it had many false reports due to conversion + * errors (which is expected since we just pass in strings), but once those + * are eliminated there aren't really any other valid error messages returned + * (for example, calling the formatter with bogus formatting flags always just + * returns a "conversion" error. It looks like we'd need to actually pass compatible + * arguments to trigger other types of formatting errors such as precision errors. if (!warned && checkValid) { try { - // Pass lots of strings. This won't match for integers etc, and - // could supply more arguments than necessary, but this is still - // less work for the virtual machine than throwing exceptions and - // complaining. - formatter.format(formatString, "", "", "", "", "", "", ""); + formatter.format(formatString, "", "", "", "", "", "", "", + "", "", "", "", "", "", ""); } catch (IllegalFormatException t) { // TODO: UnknownFormatConversionException - Location location = handle.resolve(); - if (!t.getLocalizedMessage().contains(" != ")) { + if (!t.getLocalizedMessage().contains(" != ") + && !t.getLocalizedMessage().contains("Conversion")) { + Location location = handle.resolve(); context.report(INVALID, location, String.format("Wrong format for %1$s: %2$s", name, t.getLocalizedMessage()), null); } } } + */ } } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StringFormatDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StringFormatDetectorTest.java index 6532c3f..5bd124a 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StringFormatDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StringFormatDetectorTest.java @@ -75,4 +75,12 @@ public class StringFormatDetectorTest extends AbstractCheckTest { "First: %1$s, Skip \\%2$s, Value=%2$d", 2)); } + public void testWrongSyntax() throws Exception { + assertEquals( + "No warnings.", + + lintProject( + "res/values/formatstrings2.xml" + )); + } } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/res/values/formatstrings2.xml b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/res/values/formatstrings2.xml new file mode 100644 index 0000000..23291d2 --- /dev/null +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/res/values/formatstrings2.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string name="hour_minute_24">%H:%M</string> + <string name="numeric_wday1_mdy1_time1_wday2_mdy2_time2">%5$s %1$s, %4$s-%2$s-%3$s – %10$s %6$s, %9$s-%7$s-%8$s</string> + <string name="bogus">%2.99999s</string> +</resources> |