Difference between revisions of "False Positives"

From Lingoport Wiki
Jump to: navigation, search
(Modifying Rules)
(Modifying Rules)
Line 27: Line 27:
   
 
Globalyzer identifies the string <code>New user created</code> as a candidate embedded string which should be moved out of the code and into a resource bundle. However, let's assume the developer knows that SpecialTB.write() is a method that writes some logging information into a database for potential debugging purposes. The Rule Set needs to be modified based on that knowledge so that this particular line and all other strings passed to this call will be filtered out, i.e. will not be detected as a candidate issue.
 
Globalyzer identifies the string <code>New user created</code> as a candidate embedded string which should be moved out of the code and into a resource bundle. However, let's assume the developer knows that SpecialTB.write() is a method that writes some logging information into a database for potential debugging purposes. The Rule Set needs to be modified based on that knowledge so that this particular line and all other strings passed to this call will be filtered out, i.e. will not be detected as a candidate issue.
[File:Rule SpecialTB write.gif]
+
[[File:Rule SpecialTB write.gif]]
   
 
Any Globalyzer scan using this updated rule set will henceforth filter out the embedded string issue. Many Workbench instances and the nightly builds for instance would now filter out the issue.
 
Any Globalyzer scan using this updated rule set will henceforth filter out the embedded string issue. Many Workbench instances and the nightly builds for instance would now filter out the issue.

Revision as of 19:02, 25 August 2015

What are False Positives

Globalyzer scans the source code to detect candidate issues based on rules. Given some code, a rule may detect a candidate issue. In one context, that candidate issue may need to be corrected when in another context, the same issue may not need any work and is a false positive.

Let's look at a couple of lines of Java code which creates a date string based on a hard coded date format using SimpleDateFormat:

SimpleDateFormat formatter =new SimpleDateFormat("MM/dd/yy");
String dateString = formatter.format(new Date()); 

Using the default Java rule sets, this code will raise i18n issues. If the dateString variable is user facing, this code is indeed an issue to be fixed (for more information, check your rule set help pages).

However, if the dateString variable is used for internal purposes, such as a in a support log file, it should not be modified and is a false positive.

This section describes different ways to handle rule sets.

Modifying Rules

Since Rules are what detect or filter out issues, the most common way to handle particular programming styles is to modify the rule set applied to scan a project's code.

Let's look at a string detected by Globalyzer:

SpecialTB.write("New user created");

Globalyzer identifies the string New user created as a candidate embedded string which should be moved out of the code and into a resource bundle. However, let's assume the developer knows that SpecialTB.write() is a method that writes some logging information into a database for potential debugging purposes. The Rule Set needs to be modified based on that knowledge so that this particular line and all other strings passed to this call will be filtered out, i.e. will not be detected as a candidate issue. Rule SpecialTB write.gif

Any Globalyzer scan using this updated rule set will henceforth filter out the embedded string issue. Many Workbench instances and the nightly builds for instance would now filter out the issue.

Globalyzer Comment Tags

When you want to filter out a specific item in the code, one way is to add a Globalyzer comment on the offending line. This is for a specific item and only this one. If more code is written in the same way and Globalyzer should not detect the issue, a Rule Set modification may be better.

Let's look at a simple line of code where Globalyzer detects a candidate issue, here another embedded string:

    String marker = "Marker 15";

By adding the //$NON-NLS-L$ comment at the end of the line, Globalyzer will now ignore the issue:

    String marker = "Marker 15"; //$NON-NLS-L$ 

Since the code is pushed to the source control system, the next time a Workbench user or a script gets the latest code, Globalyzer will ignore the issue.

Workbench Status

Dashboard

Feedback to Lingoport