Skip to content

Commit

Permalink
Hashmap Bug: HashMap.value() does not ensure order, updated to Linked…
Browse files Browse the repository at this point in the history
…HashMap
  • Loading branch information
playedinane committed Nov 19, 2015
1 parent 5c9278e commit 97b13a8
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/cflint/BugList.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.cflint;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand All @@ -10,7 +10,7 @@

public class BugList implements Iterable<BugInfo> {

Map<String, List<BugInfo>> bugList = new HashMap<String, List<BugInfo>>();
Map<String, List<BugInfo>> bugList = new LinkedHashMap<String, List<BugInfo>>();
/**
*
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.cflint.plugins.core;

import java.util.Map;
import java.util.HashMap;
import java.util.LinkedHashMap;

import net.htmlparser.jericho.Element;

Expand All @@ -22,8 +22,8 @@
public class UnusedArgumentChecker extends CFLintScannerAdapter {
final String severity = "INFO";

protected Map<String, Boolean> methodArguments = new HashMap<String, Boolean>();
protected Map<String, Integer> argumentLineNo = new HashMap<String, Integer>();
protected Map<String, Boolean> methodArguments = new LinkedHashMap<String, Boolean>();
protected Map<String, Integer> argumentLineNo = new LinkedHashMap<String, Integer>();

@Override
public void element(final Element element, final Context context, final BugList bugs) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.cflint.plugins.core;

import java.util.Map;
import java.util.HashMap;
import java.util.LinkedHashMap;

import cfml.parsing.cfscript.CFAssignmentExpression;
import cfml.parsing.cfscript.CFExpression;
Expand All @@ -18,8 +18,8 @@ public class UnusedLocalVarChecker extends CFLintScannerAdapter {
final String severity = "INFO";

protected CFScopes scopes = new CFScopes();
protected Map<String, Boolean> localVariables = new HashMap<String, Boolean>();
protected Map<String, Integer> variableLineNo = new HashMap<String, Integer>();
protected Map<String, Boolean> localVariables = new LinkedHashMap<String, Boolean>();
protected Map<String, Integer> variableLineNo = new LinkedHashMap<String, Integer>();

@Override
public void expression(final CFExpression expression, final Context context, final BugList bugs) {
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/com/cflint/TestCFBugs_ComponentNames.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.cflint;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.io.IOException;
import java.util.Collection;
Expand Down Expand Up @@ -115,8 +116,8 @@ public void nameTooShortTag() throws ParseException, IOException {
final String tagSrc = "<cfcomponent>\r\n"
+ "</cfcomponent>";
cfBugs.process(tagSrc, "A.cfc");
final List<BugInfo> result = cfBugs.getBugs().getBugList().values().iterator().next();
assertEquals(1, result.size());
final List<BugInfo> result = cfBugs.getBugs().getBugList().get("COMPONENT_TOO_SHORT");
assertNotNull(result);
assertEquals("COMPONENT_TOO_SHORT", result.get(0).getMessageCode());
assertEquals(1, result.get(0).getLine());
}
Expand Down Expand Up @@ -224,8 +225,8 @@ public void nameTooShortScript() throws ParseException, IOException {
final String scriptSrc = "component {\r\n"
+ "}";
cfBugs.process(scriptSrc, "A.cfc");
final List<BugInfo> result = cfBugs.getBugs().getBugList().values().iterator().next();
assertEquals(1, result.size());
final List<BugInfo> result = cfBugs.getBugs().getBugList().get("COMPONENT_TOO_SHORT");
assertNotNull(result);
assertEquals("COMPONENT_TOO_SHORT", result.get(0).getMessageCode());
assertEquals(1, result.get(0).getLine());
}
Expand Down
1 change: 0 additions & 1 deletion src/test/java/com/cflint/TestLiteralGlobalChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public void testTooManyGlobalHardCodevedValues() throws ParseException, IOExcept
scriptSrc = "<cfscript>\r\n"
+ "area = 3.14 * radius * radius;\r\n"
+ "volume = 4/3 * 3.14 * radius * radius * radius;\r\n"
+"}\r\n"
+ "</cfscript>";

cfBugs.process(scriptSrc, "test");
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/cflint/TestUnusedArgumentChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ public void testMultipleArgumentsNotUsedTag() throws ParseException, IOException
final List<BugInfo> result = cfBugs.getBugs().getBugList().values().iterator().next();
assertEquals(3, result.size());
assertEquals("UNUSED_METHOD_ARGUMENT", result.get(0).getMessageCode());
assertEquals(6, result.get(0).getLine());
assertEquals(4, result.get(0).getLine());
assertEquals("UNUSED_METHOD_ARGUMENT", result.get(1).getMessageCode());
assertEquals(4, result.get(1).getLine());
assertEquals(5, result.get(1).getLine());
assertEquals("UNUSED_METHOD_ARGUMENT", result.get(2).getMessageCode());
assertEquals(5, result.get(2).getLine());
assertEquals(6, result.get(2).getLine());
}

}
12 changes: 6 additions & 6 deletions src/test/java/com/cflint/TestUnusedLocalVarChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ public void testMultipleUnusedVarFunctionInScript() throws ParseException, IOExc
final List<BugInfo> result = cfBugs.getBugs().getBugList().values().iterator().next();
assertEquals(3, result.size());
assertEquals("UNUSED_LOCAL_VARIABLE", result.get(0).getMessageCode());
assertEquals(7, result.get(0).getLine());
assertEquals(6, result.get(0).getLine());
assertEquals("UNUSED_LOCAL_VARIABLE", result.get(1).getMessageCode());
assertEquals(8, result.get(1).getLine());
assertEquals(7, result.get(1).getLine());
assertEquals("UNUSED_LOCAL_VARIABLE", result.get(2).getMessageCode());
assertEquals(6, result.get(2).getLine());
assertEquals(8, result.get(2).getLine());
}

public void testAllUsedInTags() throws ParseException, IOException {
Expand Down Expand Up @@ -251,11 +251,11 @@ public void testMultipleUnusedVarFunctionInTag() throws ParseException, IOExcept
final List<BugInfo> result = cfBugs.getBugs().getBugList().values().iterator().next();
assertEquals(3, result.size());
assertEquals("UNUSED_LOCAL_VARIABLE", result.get(0).getMessageCode());
assertEquals(6, result.get(0).getLine());
assertEquals(5, result.get(0).getLine());
assertEquals("UNUSED_LOCAL_VARIABLE", result.get(1).getMessageCode());
assertEquals(7, result.get(1).getLine());
assertEquals(6, result.get(1).getLine());
assertEquals("UNUSED_LOCAL_VARIABLE", result.get(2).getMessageCode());
assertEquals(5, result.get(2).getLine());
assertEquals(7, result.get(2).getLine());
}

}

0 comments on commit 97b13a8

Please sign in to comment.