{"action":"opened","issue":{"url":"https://api.github.com/repos/checkstyle/checkstyle/issues/5868","repository_url":"https://api.github.com/repos/checkstyle/checkstyle","labels_url":"https://api.github.com/repos/checkstyle/checkstyle/issues/5868/labels{/name}","comments_url":"https://api.github.com/repos/checkstyle/checkstyle/issues/5868/comments","events_url":"https://api.github.com/repos/checkstyle/checkstyle/issues/5868/events","html_url":"https://github.com/checkstyle/checkstyle/issues/5868","id":327314517,"number":5868,"title":"Missed elements in the combined xpath query","user":{"login":"timurt","id":1443064,"avatar_url":"https://avatars3.githubusercontent.com/u/1443064?v=4","gravatar_id":"","url":"https://api.github.com/users/timurt","html_url":"https://github.com/timurt","followers_url":"https://api.github.com/users/timurt/followers","following_url":"https://api.github.com/users/timurt/following{/other_user}","gists_url":"https://api.github.com/users/timurt/gists{/gist_id}","starred_url":"https://api.github.com/users/timurt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timurt/subscriptions","organizations_url":"https://api.github.com/users/timurt/orgs","repos_url":"https://api.github.com/users/timurt/repos","events_url":"https://api.github.com/users/timurt/events{/privacy}","received_events_url":"https://api.github.com/users/timurt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-05-29T13:12:18Z","updated_at":"2018-05-29T13:12:18Z","closed_at":null,"author_association":"COLLABORATOR","body":"The order of xpath queries in the combined query affects the returned result, nodes those satisfy query can be missed.\r\n\r\nSteps to reproduce:\r\n\r\n**Java class**\r\n```\r\n/var/tmp $ cat InputTest.java\r\npublic class InputTest {\r\n    public void test(int a, int b) {\r\n        if (a > b) {\r\n\r\n        } else {\r\n\r\n        }\r\n    }\r\n\r\n    public void foo2() {\r\n        String programmingLanguage = \"Java\";\r\n        switch (programmingLanguage) {\r\n            case \"Java\":\r\n            case \"C#\":\r\n            case \"C++\":\r\n                String.CASE_INSENSITIVE_ORDER.equals(programmingLanguage + \" is an object oriented programming language.\");\r\n                break;\r\n            case \"C\":\r\n                String.CASE_INSENSITIVE_ORDER.equals(programmingLanguage + \" is not an object oriented programming language.\");\r\n                break;\r\n            default:\r\n                String.CASE_INSENSITIVE_ORDER.equals(programmingLanguage + \" is unknown language.\");\r\n                break;\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n**Config file**\r\n```\r\n/var/tmp $ cat config.xml\r\n<?xml version=\"1.0\"?>\r\n<!DOCTYPE module PUBLIC\r\n          \"-//Puppy Crawl//DTD Check Configuration 1.3//EN\"\r\n          \"http://www.puppycrawl.com/dtds/configuration_1_3.dtd\">\r\n\r\n<module name=\"Checker\">\r\n    <property name=\"charset\" value=\"UTF-8\"/>\r\n\r\n    <module name=\"TreeWalker\">\r\n      <module name=\"CyclomaticComplexity\">\r\n    \t <property name=\"max\" value=\"0\"/>\r\n      </module>\r\n    </module>\r\n</module>\r\n```\r\n\r\n**Executing checkstyle**\r\n```\r\n/var/tmp $ java $RUN_LOCALE -jar checkstyle-X.XX-all.jar -c config.xml InputTest.java\r\nStarting audit...\r\n[ERROR] /var/tmp/InputTest.java:2:5: Cyclomatic Complexity is 2 (max allowed is 0). [CyclomaticComplexity]\r\n[ERROR] /var/tmp/InputTest.java:10:5: Cyclomatic Complexity is 5 (max allowed is 0). [CyclomaticComplexity]\r\nAudit done.\r\nCheckstyle ends with 2 errors.\r\n```\r\n\r\n**Generating xpath queries**\r\nFor each violation message we generate xpath queries using line number and column number of the violation\r\n\r\n```\r\n/var/tmp $ java $RUN_LOCALE -jar checkstyle-X.XX-all.jar -s 2:5 InputTest.java\r\n/CLASS_DEF[@text='InputTest']/OBJBLOCK/METHOD_DEF[@text='test']\r\n/CLASS_DEF[@text='InputTest']/OBJBLOCK/METHOD_DEF[@text='test']/MODIFIERS\r\n/CLASS_DEF[@text='InputTest']/OBJBLOCK/METHOD_DEF[@text='test']/MODIFIERS/LITERAL_PUBLIC\r\n\r\n/var/tmp $ java $RUN_LOCALE -jar checkstyle-X.XX-all.jar -s 10:5 InputTest.java\r\n/CLASS_DEF[@text='InputTest']/OBJBLOCK/METHOD_DEF[@text='foo2']\r\n/CLASS_DEF[@text='InputTest']/OBJBLOCK/METHOD_DEF[@text='foo2']/MODIFIERS\r\n/CLASS_DEF[@text='InputTest']/OBJBLOCK/METHOD_DEF[@text='foo2']/MODIFIERS/LITERAL_PUBLIC\r\n```\r\n\r\n**Updated config file**\r\n`SuppressionXpathFilter` module was added\r\n```\r\n/var/tmp $ cat config.xml\r\n<?xml version=\"1.0\"?>\r\n<!DOCTYPE module PUBLIC\r\n          \"-//Puppy Crawl//DTD Check Configuration 1.3//EN\"\r\n          \"http://www.puppycrawl.com/dtds/configuration_1_3.dtd\">\r\n\r\n<module name=\"Checker\">\r\n    <property name=\"charset\" value=\"UTF-8\"/>\r\n\r\n    <module name=\"TreeWalker\">\r\n      <module name=\"CyclomaticComplexity\">\r\n    \t <property name=\"max\" value=\"0\"/>\r\n      </module>\r\n      <module name=\"SuppressionXpathFilter\">\r\n\t <property name=\"file\" value=\"suppressions_xpath.xml\"/>\r\n      </module>\r\n    </module>\r\n</module>\r\n```\r\n\r\n**Suppressions File**\r\nLet's combine all xpath queries using `|` delimeter and execute checkstyle\r\n```\r\n/var/tmp $ cat suppressions_xpath.xml\r\n<?xml version=\"1.0\"?>\r\n\r\n<!DOCTYPE suppressions PUBLIC\r\n    \"-//Puppy Crawl//DTD Suppressions Xpath Experimental 1.2//EN\"\r\n    \"http://checkstyle.sourceforge.net/dtds/suppressions_1_2_xpath_experimental.dtd\">\r\n\r\n<suppressions>\r\n    <suppress-xpath checks=\"CyclomaticComplexity\"\r\n        query=\"/CLASS_DEF[@text='InputTest']/OBJBLOCK/METHOD_DEF[@text='test'] | \r\n/CLASS_DEF[@text='InputTest']/OBJBLOCK/METHOD_DEF[@text='test']/MODIFIERS | \r\n/CLASS_DEF[@text='InputTest']/OBJBLOCK/METHOD_DEF[@text='test']/MODIFIERS/LITERAL_PUBLIC | \r\n/CLASS_DEF[@text='InputTest']/OBJBLOCK/METHOD_DEF[@text='foo2'] | \r\n/CLASS_DEF[@text='InputTest']/OBJBLOCK/METHOD_DEF[@text='foo2']/MODIFIERS | \r\n/CLASS_DEF[@text='InputTest']/OBJBLOCK/METHOD_DEF[@text='foo2']/MODIFIERS/LITERAL_PUBLIC\"/>\r\n</suppressions>\r\n```\r\n**Executing checkstyle**\r\nTwo errors should have been suppressed, but for some reason, the first error was not suppressed\r\n```\r\n/var/tmp $ java $RUN_LOCALE -jar checkstyle-X.XX-all.jar -c config.xml InputTest.java\r\nStarting audit...\r\n[ERROR] /Users/timurtibeyev/Documents/test/CyclomaticComplexityCheck/InputTest.java:2:5: Cyclomatic Complexity is 2 (max allowed is 0). [CyclomaticComplexity]\r\nAudit done.\r\nCheckstyle ends with 1 errors.\r\n```\r\n\r\n**Suppressions File**\r\nLet's rearrange queries, move fourth query to second place and test again\r\n```\r\n/var/tmp $ cat suppressions_xpath.xml\r\n<?xml version=\"1.0\"?>\r\n\r\n<!DOCTYPE suppressions PUBLIC\r\n    \"-//Puppy Crawl//DTD Suppressions Xpath Experimental 1.2//EN\"\r\n    \"http://checkstyle.sourceforge.net/dtds/suppressions_1_2_xpath_experimental.dtd\">\r\n\r\n<suppressions>\r\n    <suppress-xpath checks=\"CyclomaticComplexity\"\r\n        query=\"/CLASS_DEF[@text='InputTest']/OBJBLOCK/METHOD_DEF[@text='test'] | \r\n/CLASS_DEF[@text='InputTest']/OBJBLOCK/METHOD_DEF[@text='foo2'] | \r\n/CLASS_DEF[@text='InputTest']/OBJBLOCK/METHOD_DEF[@text='test']/MODIFIERS | \r\n/CLASS_DEF[@text='InputTest']/OBJBLOCK/METHOD_DEF[@text='test']/MODIFIERS/LITERAL_PUBLIC | \r\n/CLASS_DEF[@text='InputTest']/OBJBLOCK/METHOD_DEF[@text='foo2']/MODIFIERS | \r\n/CLASS_DEF[@text='InputTest']/OBJBLOCK/METHOD_DEF[@text='foo2']/MODIFIERS/LITERAL_PUBLIC\"/>\r\n</suppressions>\r\n```\r\n\r\n**Executing checkstyle**\r\nNo violation occurred\r\n\r\n```\r\n/var/tmp $ java $RUN_LOCALE -jar checkstyle-X.XX-all.jar -c config.xml InputTest.java\r\nStarting audit...\r\nAudit done.\r\n```\r\n"}}
{"actor":{"display_login":"timurt"}}