{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/75820009","id":75820009,"diff_hunk":"@@ -362,92 +364,79 @@ public final void testUnknownObjectException() throws IOException {\n      * }\n      */\n     private void unknownObjectExceptionTest(String validQuery) throws IOException {\n-        //TODO building json by concatenating strings makes the code unmaintainable, we should rewrite this test\n-        assertThat(validQuery, containsString(\"{\"));\n-        int level = 0;\n-        //track whether we are within quotes as we may have randomly generated strings containing curly brackets\n-        boolean withinQuotes = false;\n-        boolean expectedException = true;\n-        int objectHoldingArbitraryContentLevel = 0;\n-        for (int insertionPosition = 0; insertionPosition < validQuery.length(); insertionPosition++) {\n-            if (validQuery.charAt(insertionPosition) == '\"') {\n-                withinQuotes = withinQuotes == false;\n-            } else if (withinQuotes == false && validQuery.charAt(insertionPosition) == '}') {\n-                level--;\n-                if (expectedException == false) {\n-                    //track where we are within the object that holds arbitrary content\n-                    objectHoldingArbitraryContentLevel--;\n-                }\n-                if (objectHoldingArbitraryContentLevel == 0) {\n-                    //reset the flag once we have traversed the whole object that holds arbitrary content\n-                    expectedException = true;\n-                }\n-            } else if (withinQuotes == false && validQuery.charAt(insertionPosition) == '{') {\n-                //keep track of which level we are within the json so that we can properly close the additional object\n-                level++;\n-                //if we don't expect an exception, it means that we are within an object that can contain arbitrary content.\n-                //in that case we ignore the whole object including its children, no need to even check where we are.\n-                if (expectedException) {\n-                    int startCurrentObjectName = -1;\n-                    int endCurrentObjectName = -1;\n-                    //look backwards for the current object name, to find out whether we expect an exception following its mutation\n-                    for (int i = insertionPosition; i >= 0; i--) {\n-                        if (validQuery.charAt(i) == '}') {\n-                            break;\n-                        } else if (validQuery.charAt(i) == '\"') {\n-                            if (endCurrentObjectName == -1) {\n-                                endCurrentObjectName = i;\n-                            } else if (startCurrentObjectName == -1) {\n-                                startCurrentObjectName = i + 1;\n-                            } else {\n-                                break;\n+        // Track the number of query mutations\n+        int mutation = 0;\n+\n+        // Indicate if a part of the query can hold any arbitrary content\n+        boolean hasArbitraryContent = getObjectsHoldingArbitraryContent().isEmpty() == false;\n+\n+        while(true) {","path":"test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java","position":null,"original_position":76,"commit_id":"feb49ad2d1ed197e622dd1804b21ee2add3e76da","original_commit_id":"06f9ec7d47cd567780cdc3d02d5eb239dab452c5","user":{"login":"tlrx","id":642733,"avatar_url":"https://avatars.githubusercontent.com/u/642733?v=3","gravatar_id":"","url":"https://api.github.com/users/tlrx","html_url":"https://github.com/tlrx","followers_url":"https://api.github.com/users/tlrx/followers","following_url":"https://api.github.com/users/tlrx/following{/other_user}","gists_url":"https://api.github.com/users/tlrx/gists{/gist_id}","starred_url":"https://api.github.com/users/tlrx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tlrx/subscriptions","organizations_url":"https://api.github.com/users/tlrx/orgs","repos_url":"https://api.github.com/users/tlrx/repos","events_url":"https://api.github.com/users/tlrx/events{/privacy}","received_events_url":"https://api.github.com/users/tlrx/received_events","type":"User","site_admin":false},"body":"It makes sense, I split the method and added `AbstractQueryTestCaseTests`, let me know what you think.","created_at":"2016-08-23T08:17:07Z","updated_at":"2016-08-23T08:17:07Z","html_url":"https://github.com/elastic/elasticsearch/pull/20100#discussion_r75820009","pull_request_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/20100","_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/75820009"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/20100#discussion_r75820009"},"pull_request":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/20100"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/20100","id":82166049,"html_url":"https://github.com/elastic/elasticsearch/pull/20100","diff_url":"https://github.com/elastic/elasticsearch/pull/20100.diff","patch_url":"https://github.com/elastic/elasticsearch/pull/20100.patch","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/20100","number":20100,"state":"open","locked":false,"title":"[Test] Improve AbstractQueryTestCase.unknownObjectExceptionTest()","user":{"login":"tlrx","id":642733,"avatar_url":"https://avatars.githubusercontent.com/u/642733?v=3","gravatar_id":"","url":"https://api.github.com/users/tlrx","html_url":"https://github.com/tlrx","followers_url":"https://api.github.com/users/tlrx/followers","following_url":"https://api.github.com/users/tlrx/following{/other_user}","gists_url":"https://api.github.com/users/tlrx/gists{/gist_id}","starred_url":"https://api.github.com/users/tlrx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tlrx/subscriptions","organizations_url":"https://api.github.com/users/tlrx/orgs","repos_url":"https://api.github.com/users/tlrx/repos","events_url":"https://api.github.com/users/tlrx/events{/privacy}","received_events_url":"https://api.github.com/users/tlrx/received_events","type":"User","site_admin":false},"body":"The method `AbstractQueryTestCase.unknownObjectExceptionTest()` uses heavy string concatenation to modify and insert new field in a valid query. Unfortunately it fails when a randomized string value contains a `\"`. Since the test method is hard to understand and maintain, this PR changes it to a XContent based parsing and generating.\r\n\r\nThis has been detected by CI:\r\n\r\n> REPRODUCE WITH: gradle :core:test -Dtests.seed=5284243AD94E27EC -Dtests.class=org.elasticsearch.index.query.SpanOrQueryBuilderTests -Dtests.method=\"testUnknownObjectException\" -Dtests.security.manager=true -Dtests.locale=lv -Dtests.timezone=Canada/Yukon\r\nSuite: org.elasticsearch.index.query.SpanOrQueryBuilderTests\r\n  1> [2016-08-19 09:20:55,894][INFO ][org.elasticsearch.cluster.service] new_master {node}{vb3qT855T--Ej-ybWKgRsw}{local}{local[816]}, reason: test setting state\r\n  1> [2016-08-19 09:20:55,895][INFO ][org.elasticsearch.plugins] [class org.elasticsearch.test.AbstractQueryTestCase] no modules loaded\r\n  1> [2016-08-19 09:20:55,895][INFO ][org.elasticsearch.plugins] [class org.elasticsearch.test.AbstractQueryTestCase] no plugins loaded\r\nERROR   0.01s J1 | SpanOrQueryBuilderTests.testUnknownObjectException <<< FAILURES!\r\n   > Throwable #1: com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input within/between Object entries\r\n   >  at [Source: { \"newField\" : ; line: 1, column: 31]\r\n   > \tat __randomizedtesting.SeedInfo.seed([5284243AD94E27EC:FA9AD57BE440E8EE]:0)\r\n   > \tat com.fasterxml.jackson.core.base.ParserMinimalBase._reportInvalidEOF(ParserMinimalBase.java:483)\r\n   > \tat com.fasterxml.jackson.core.json.ReaderBasedJsonParser._skipColon2(ReaderBasedJsonParser.java:2229)\r\n   > \tat com.fasterxml.jackson.core.json.ReaderBasedJsonParser._skipColon(ReaderBasedJsonParser.java:2141)\r\n  2> NOTE: leaving temporary files on disk at: /usr/share/elasticsearch/escheckout/core/build/testrun/test/J1/temp/org.elasticsearch.index.query.SpanOrQueryBuilderTests_5284243AD94E27EC-001\r\n   > \tat com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:687)\r\n   > \tat org.elasticsearch.common.xcontent.json.JsonXContentParser.nextToken(JsonXContentParser.java:52)\r\n   > \tat org.elasticsearch.index.query.QueryParseContext.parseInnerQueryBuilder(QueryParseContext.java:96)\r\n  2> NOTE: test params are: codec=Asserting(Lucene60): {}, docValues:{}, maxPointsInLeafNode=1463, maxMBSortInHeap=7.289747265721868, sim=ClassicSimilarity, locale=lv, timezone=Canada/Yukon\r\n  2> NOTE: Linux 4.4.0-31-generic amd64/Oracle Corporation 1.8.0_92-internal (64-bit)/cpus=4,threads=1,free=451550800,total=530055168\r\n   > \tat org.elasticsearch.test.AbstractQueryTestCase.parseQuery(AbstractQueryTestCase.java:566)\r\n   > \tat org.elasticsearch.test.AbstractQueryTestCase.parseQuery(AbstractQueryTestCase.java:552)\r\n   > \tat org.elasticsearch.test.AbstractQueryTestCase.parseQuery(AbstractQueryTestCase.java:547)\r\n   > \tat org.elasticsearch.test.AbstractQueryTestCase.unknownObjectExceptionTest(AbstractQueryTestCase.java:436)\r\n   > \tat org.elasticsearch.test.AbstractQueryTestCase.testUnknownObjectException(AbstractQueryTestCase.java:321)\r\n   > \tat java.lang.Thread.run(Thread.java:745) \r\n\r\nRelated to #19864","created_at":"2016-08-22T10:19:54Z","updated_at":"2016-08-23T08:17:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6607ebd64ad4c9dd9653b96c3703efbf9fe776c6","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/20100/commits","review_comments_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/20100/comments","review_comment_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/20100/comments","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/feb49ad2d1ed197e622dd1804b21ee2add3e76da","head":{"label":"tlrx:fix-abstract-builder-tests","ref":"fix-abstract-builder-tests","sha":"feb49ad2d1ed197e622dd1804b21ee2add3e76da","user":{"login":"tlrx","id":642733,"avatar_url":"https://avatars.githubusercontent.com/u/642733?v=3","gravatar_id":"","url":"https://api.github.com/users/tlrx","html_url":"https://github.com/tlrx","followers_url":"https://api.github.com/users/tlrx/followers","following_url":"https://api.github.com/users/tlrx/following{/other_user}","gists_url":"https://api.github.com/users/tlrx/gists{/gist_id}","starred_url":"https://api.github.com/users/tlrx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tlrx/subscriptions","organizations_url":"https://api.github.com/users/tlrx/orgs","repos_url":"https://api.github.com/users/tlrx/repos","events_url":"https://api.github.com/users/tlrx/events{/privacy}","received_events_url":"https://api.github.com/users/tlrx/received_events","type":"User","site_admin":false},"repo":{"id":24718639,"name":"elasticsearch","full_name":"tlrx/elasticsearch","owner":{"login":"tlrx","id":642733,"avatar_url":"https://avatars.githubusercontent.com/u/642733?v=3","gravatar_id":"","url":"https://api.github.com/users/tlrx","html_url":"https://github.com/tlrx","followers_url":"https://api.github.com/users/tlrx/followers","following_url":"https://api.github.com/users/tlrx/following{/other_user}","gists_url":"https://api.github.com/users/tlrx/gists{/gist_id}","starred_url":"https://api.github.com/users/tlrx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tlrx/subscriptions","organizations_url":"https://api.github.com/users/tlrx/orgs","repos_url":"https://api.github.com/users/tlrx/repos","events_url":"https://api.github.com/users/tlrx/events{/privacy}","received_events_url":"https://api.github.com/users/tlrx/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tlrx/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":true,"url":"https://api.github.com/repos/tlrx/elasticsearch","forks_url":"https://api.github.com/repos/tlrx/elasticsearch/forks","keys_url":"https://api.github.com/repos/tlrx/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tlrx/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tlrx/elasticsearch/teams","hooks_url":"https://api.github.com/repos/tlrx/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/tlrx/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/tlrx/elasticsearch/events","assignees_url":"https://api.github.com/repos/tlrx/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/tlrx/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/tlrx/elasticsearch/tags","blobs_url":"https://api.github.com/repos/tlrx/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tlrx/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tlrx/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/tlrx/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tlrx/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/tlrx/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/tlrx/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/tlrx/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/tlrx/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/tlrx/elasticsearch/subscription","commits_url":"https://api.github.com/repos/tlrx/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/tlrx/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/tlrx/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/tlrx/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/tlrx/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/tlrx/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tlrx/elasticsearch/merges","archive_url":"https://api.github.com/repos/tlrx/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tlrx/elasticsearch/downloads","issues_url":"https://api.github.com/repos/tlrx/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/tlrx/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/tlrx/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/tlrx/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tlrx/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/tlrx/elasticsearch/releases{/id}","deployments_url":"https://api.github.com/repos/tlrx/elasticsearch/deployments","created_at":"2014-10-02T12:51:44Z","updated_at":"2014-10-02T08:42:36Z","pushed_at":"2016-08-23T08:16:22Z","git_url":"git://github.com/tlrx/elasticsearch.git","ssh_url":"git@github.com:tlrx/elasticsearch.git","clone_url":"https://github.com/tlrx/elasticsearch.git","svn_url":"https://github.com/tlrx/elasticsearch","homepage":"http://elasticsearch.org","size":202445,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"elastic:master","ref":"master","sha":"8136c91cf0addbc676b784661c52e78ea4b3e74b","user":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"repo":{"id":507775,"name":"elasticsearch","full_name":"elastic/elasticsearch","owner":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elastic/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":false,"url":"https://api.github.com/repos/elastic/elasticsearch","forks_url":"https://api.github.com/repos/elastic/elasticsearch/forks","keys_url":"https://api.github.com/repos/elastic/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elastic/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elastic/elasticsearch/teams","hooks_url":"https://api.github.com/repos/elastic/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/elastic/elasticsearch/events","assignees_url":"https://api.github.com/repos/elastic/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/elastic/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/elastic/elasticsearch/tags","blobs_url":"https://api.github.com/repos/elastic/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elastic/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elastic/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/elastic/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/elastic/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/elastic/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/elastic/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/elastic/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/elastic/elasticsearch/subscription","commits_url":"https://api.github.com/repos/elastic/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/elastic/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/elastic/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/elastic/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elastic/elasticsearch/merges","archive_url":"https://api.github.com/repos/elastic/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elastic/elasticsearch/downloads","issues_url":"https://api.github.com/repos/elastic/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/elastic/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/elastic/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/elastic/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elastic/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/elastic/elasticsearch/releases{/id}","deployments_url":"https://api.github.com/repos/elastic/elasticsearch/deployments","created_at":"2010-02-08T13:20:56Z","updated_at":"2016-08-23T08:14:57Z","pushed_at":"2016-08-23T08:16:23Z","git_url":"git://github.com/elastic/elasticsearch.git","ssh_url":"git@github.com:elastic/elasticsearch.git","clone_url":"https://github.com/elastic/elasticsearch.git","svn_url":"https://github.com/elastic/elasticsearch","homepage":"https://www.elastic.co/products/elasticsearch","size":341148,"stargazers_count":18056,"watchers_count":18056,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6105,"mirror_url":null,"open_issues_count":1124,"forks":6105,"open_issues":1124,"watchers":18056,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/20100"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/20100"},"issue":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/20100"},"comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/20100/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/20100/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/20100/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/elasticsearch/statuses/feb49ad2d1ed197e622dd1804b21ee2add3e76da"}}}}
{"actor":{"display_login":"tlrx"}}