[Fb-contrib-commit] SF.net SVN: fb-contrib:[1699] trunk/fb-contrib
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2011-07-05 00:44:33
|
Revision: 1699
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1699&view=rev
Author: dbrosius
Date: 2011-07-05 00:44:27 +0000 (Tue, 05 Jul 2011)
Log Message:
-----------
add S508C_APPENDED_STRING bug pattern
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/samples/S508C_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2011-07-04 23:47:34 UTC (rev 1698)
+++ trunk/fb-contrib/etc/findbugs.xml 2011-07-05 00:44:27 UTC (rev 1699)
@@ -103,7 +103,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.NonRecycleableTaglibs" speed="fast" reports="NRTL_NON_RECYCLEABLE_TAG_LIB" />
<Detector class="com.mebigfatguy.fbcontrib.detect.Section508Compliance" speed="fast"
- reports="S508C_NULL_LAYOUT,S508C_NO_SETLABELFOR,S508C_NO_SETSIZE,S508C_NON_ACCESSIBLE_JCOMPONENT,S508C_SET_COMP_COLOR,S508C_NON_TRANSLATABLE_STRING" />
+ reports="S508C_NULL_LAYOUT,S508C_NO_SETLABELFOR,S508C_NO_SETSIZE,S508C_NON_ACCESSIBLE_JCOMPONENT,S508C_SET_COMP_COLOR,S508C_NON_TRANSLATABLE_STRING,S508C_APPENDED_STRING" />
<Detector class="com.mebigfatguy.fbcontrib.detect.UseEnumCollections" speed="fast" reports="UEC_USE_ENUM_COLLECTIONS" />
@@ -282,6 +282,7 @@
<BugPattern abbrev="S508C" type="S508C_NON_ACCESSIBLE_JCOMPONENT" category="CORRECTNESS" />
<BugPattern abbrev="S508C" type="S508C_SET_COMP_COLOR" category="CORRECTNESS" />
<BugPattern abbrev="S508C" type="S508C_NON_TRANSLATABLE_STRING" category="CORRECTNESS" />
+ <BugPattern abbrev="S508C" type="S508C_APPENDED_STRING" category="CORRECTNESS" />
<BugPattern abbrev="UEC" type="UEC_USE_ENUM_COLLECTIONS" category="PERFORMANCE" />
<BugPattern abbrev="SIL" type="SIL_SQL_IN_LOOP" category="PERFORMANCE" />
<BugPattern abbrev="NMCS" type="NMCS_NEEDLESS_MEMBER_COLLECTION_SYNCHRONIZATION" category="PERFORMANCE" />
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2011-07-04 23:47:34 UTC (rev 1698)
+++ trunk/fb-contrib/etc/messages.xml 2011-07-05 00:44:27 UTC (rev 1699)
@@ -1975,6 +1975,18 @@
]]>
</Details>
</BugPattern>
+
+ <BugPattern type="S508C_APPENDED_STRING">
+ <ShortDescription>Method passes appended string to title/label of component</ShortDescription>
+ <LongDescription>Method {1} passes appended string to title/label of component</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method creates a component and passes a string that was build up from a number of
+ strings through appending multiple strings together. As foreign languages may order phrases
+ differently, this will make translations difficult.</p>
+ ]]>
+ </Details>
+ </BugPattern>
<BugPattern type="UEC_USE_ENUM_COLLECTIONS">
<ShortDescription>Class uses an ordinary set or map with an enum class as the key</ShortDescription>
Modified: trunk/fb-contrib/samples/S508C_Sample.java
===================================================================
--- trunk/fb-contrib/samples/S508C_Sample.java 2011-07-04 23:47:34 UTC (rev 1698)
+++ trunk/fb-contrib/samples/S508C_Sample.java 2011-07-05 00:44:27 UTC (rev 1699)
@@ -35,6 +35,11 @@
JLabel l = new JLabel("Hello");
JFrame f = new JFrame("foo");
}
+
+ public void testAppending(String greeting, String user)
+ {
+ JLabel l = new JLabel(greeting + " " + user);
+ }
}
class MyComponent extends JComponent
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2011-07-04 23:47:34 UTC (rev 1698)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2011-07-05 00:44:27 UTC (rev 1699)
@@ -49,6 +49,7 @@
{
private static final String SAW_TEXT_LABEL = "SAW_TEXT_LABEL";
private static final String FROM_UIMANAGER = "FROM_UIMANAGER";
+ private static final String APPENDED_STRING = "APPENDED_STRING";
private static JavaClass windowClass;
private static JavaClass componentClass;
@@ -204,6 +205,7 @@
public void sawOpcode(int seen) {
boolean sawTextLabel = false;
boolean sawUIManager = false;
+ boolean sawAppend = false;
try {
stack.mergeJumps(this);
if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) {
@@ -252,6 +254,17 @@
}
}
}
+ } else if ("java/lang/StringBuffer".equals(className) || "java/lang/StringBuilder".equals(className)) {
+ if ("append".equals(methodName)) {
+ sawAppend = true;
+ } else if ("toString".equals(methodName)) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ if (APPENDED_STRING.equals(item.getUserValue())) {
+ sawAppend = true;
+ }
+ }
+ }
}
processSetSizeOps(methodName);
@@ -264,7 +277,7 @@
}
if ((seen == INVOKEVIRTUAL) || (seen == INVOKESPECIAL) || (seen == INVOKEINTERFACE)) {
- processUntranslatableStrings();
+ processFaultyGuiStrings();
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
@@ -280,14 +293,21 @@
OpcodeStack.Item item = stack.getStackItem(0);
item.setUserValue(FROM_UIMANAGER);
}
+ } else if (sawAppend) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ item.setUserValue(APPENDED_STRING);
+ }
}
}
}
/**
- * looks for calls to set a readable string that is generated from a static constant.
+ * looks for calls to set a readable string that is generated from a static constant, as these strings
+ * are not translatable. also looks for setting readable strings that are appended together. This is
+ * likely not to be internationalizable.
*/
- private void processUntranslatableStrings() {
+ private void processFaultyGuiStrings() {
StringBuilder methodInfo = new StringBuilder();
methodInfo.append(getClassConstantOperand());
methodInfo.append("#");
@@ -304,6 +324,12 @@
.addClass(this)
.addMethod(this)
.addSourceLine(this));
+ } else if (APPENDED_STRING.equals(item.getUserValue())) {
+ bugReporter.reportBug(new BugInstance(this, "S508C_APPENDED_STRING", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|