From 97b13a8aa834aaab17e26ab6bb7e8ccc50712023 Mon Sep 17 00:00:00 2001 From: Daniel Payne Date: Thu, 19 Nov 2015 15:31:55 +1100 Subject: [PATCH] Hashmap Bug: HashMap.value() does not ensure order, updated to LinkedHashMap --- src/main/java/com/cflint/BugList.java | 4 ++-- .../cflint/plugins/core/UnusedArgumentChecker.java | 6 +++--- .../cflint/plugins/core/UnusedLocalVarChecker.java | 6 +++--- .../java/com/cflint/TestCFBugs_ComponentNames.java | 9 +++++---- .../java/com/cflint/TestLiteralGlobalChecker.java | 1 - .../java/com/cflint/TestUnusedArgumentChecker.java | 6 +++--- .../java/com/cflint/TestUnusedLocalVarChecker.java | 12 ++++++------ 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/cflint/BugList.java b/src/main/java/com/cflint/BugList.java index 4c670a384..4131a5eab 100644 --- a/src/main/java/com/cflint/BugList.java +++ b/src/main/java/com/cflint/BugList.java @@ -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; @@ -10,7 +10,7 @@ public class BugList implements Iterable { - Map> bugList = new HashMap>(); + Map> bugList = new LinkedHashMap>(); /** * */ diff --git a/src/main/java/com/cflint/plugins/core/UnusedArgumentChecker.java b/src/main/java/com/cflint/plugins/core/UnusedArgumentChecker.java index 95ddff2a3..510029eda 100644 --- a/src/main/java/com/cflint/plugins/core/UnusedArgumentChecker.java +++ b/src/main/java/com/cflint/plugins/core/UnusedArgumentChecker.java @@ -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; @@ -22,8 +22,8 @@ public class UnusedArgumentChecker extends CFLintScannerAdapter { final String severity = "INFO"; - protected Map methodArguments = new HashMap(); - protected Map argumentLineNo = new HashMap(); + protected Map methodArguments = new LinkedHashMap(); + protected Map argumentLineNo = new LinkedHashMap(); @Override public void element(final Element element, final Context context, final BugList bugs) { diff --git a/src/main/java/com/cflint/plugins/core/UnusedLocalVarChecker.java b/src/main/java/com/cflint/plugins/core/UnusedLocalVarChecker.java index 5af9f7e40..e7c696c71 100644 --- a/src/main/java/com/cflint/plugins/core/UnusedLocalVarChecker.java +++ b/src/main/java/com/cflint/plugins/core/UnusedLocalVarChecker.java @@ -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; @@ -18,8 +18,8 @@ public class UnusedLocalVarChecker extends CFLintScannerAdapter { final String severity = "INFO"; protected CFScopes scopes = new CFScopes(); - protected Map localVariables = new HashMap(); - protected Map variableLineNo = new HashMap(); + protected Map localVariables = new LinkedHashMap(); + protected Map variableLineNo = new LinkedHashMap(); @Override public void expression(final CFExpression expression, final Context context, final BugList bugs) { diff --git a/src/test/java/com/cflint/TestCFBugs_ComponentNames.java b/src/test/java/com/cflint/TestCFBugs_ComponentNames.java index 233101ffb..529a56ef3 100644 --- a/src/test/java/com/cflint/TestCFBugs_ComponentNames.java +++ b/src/test/java/com/cflint/TestCFBugs_ComponentNames.java @@ -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; @@ -115,8 +116,8 @@ public void nameTooShortTag() throws ParseException, IOException { final String tagSrc = "\r\n" + ""; cfBugs.process(tagSrc, "A.cfc"); - final List result = cfBugs.getBugs().getBugList().values().iterator().next(); - assertEquals(1, result.size()); + final List result = cfBugs.getBugs().getBugList().get("COMPONENT_TOO_SHORT"); + assertNotNull(result); assertEquals("COMPONENT_TOO_SHORT", result.get(0).getMessageCode()); assertEquals(1, result.get(0).getLine()); } @@ -224,8 +225,8 @@ public void nameTooShortScript() throws ParseException, IOException { final String scriptSrc = "component {\r\n" + "}"; cfBugs.process(scriptSrc, "A.cfc"); - final List result = cfBugs.getBugs().getBugList().values().iterator().next(); - assertEquals(1, result.size()); + final List result = cfBugs.getBugs().getBugList().get("COMPONENT_TOO_SHORT"); + assertNotNull(result); assertEquals("COMPONENT_TOO_SHORT", result.get(0).getMessageCode()); assertEquals(1, result.get(0).getLine()); } diff --git a/src/test/java/com/cflint/TestLiteralGlobalChecker.java b/src/test/java/com/cflint/TestLiteralGlobalChecker.java index c4c2689a8..b121a86b7 100644 --- a/src/test/java/com/cflint/TestLiteralGlobalChecker.java +++ b/src/test/java/com/cflint/TestLiteralGlobalChecker.java @@ -81,7 +81,6 @@ public void testTooManyGlobalHardCodevedValues() throws ParseException, IOExcept scriptSrc = "\r\n" + "area = 3.14 * radius * radius;\r\n" + "volume = 4/3 * 3.14 * radius * radius * radius;\r\n" - +"}\r\n" + ""; cfBugs.process(scriptSrc, "test"); diff --git a/src/test/java/com/cflint/TestUnusedArgumentChecker.java b/src/test/java/com/cflint/TestUnusedArgumentChecker.java index 7b4c1a7a1..f6084c0be 100644 --- a/src/test/java/com/cflint/TestUnusedArgumentChecker.java +++ b/src/test/java/com/cflint/TestUnusedArgumentChecker.java @@ -220,11 +220,11 @@ public void testMultipleArgumentsNotUsedTag() throws ParseException, IOException final List 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()); } } diff --git a/src/test/java/com/cflint/TestUnusedLocalVarChecker.java b/src/test/java/com/cflint/TestUnusedLocalVarChecker.java index e3bec8bc1..03c5d945e 100644 --- a/src/test/java/com/cflint/TestUnusedLocalVarChecker.java +++ b/src/test/java/com/cflint/TestUnusedLocalVarChecker.java @@ -144,11 +144,11 @@ public void testMultipleUnusedVarFunctionInScript() throws ParseException, IOExc final List 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 { @@ -251,11 +251,11 @@ public void testMultipleUnusedVarFunctionInTag() throws ParseException, IOExcept final List 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()); } }