{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch-hadoop/issues/488","labels_url":"https://api.github.com/repos/elastic/elasticsearch-hadoop/issues/488/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch-hadoop/issues/488/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch-hadoop/issues/488/events","html_url":"https://github.com/elastic/elasticsearch-hadoop/pull/488","id":92165006,"number":488,"title":"Fixing NPE on close in RestRepository","user":{"login":"redowl","id":1513344,"avatar_url":"https://avatars.githubusercontent.com/u/1513344?v=3","gravatar_id":"","url":"https://api.github.com/users/redowl","html_url":"https://github.com/redowl","followers_url":"https://api.github.com/users/redowl/followers","following_url":"https://api.github.com/users/redowl/following{/other_user}","gists_url":"https://api.github.com/users/redowl/gists{/gist_id}","starred_url":"https://api.github.com/users/redowl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/redowl/subscriptions","organizations_url":"https://api.github.com/users/redowl/orgs","repos_url":"https://api.github.com/users/redowl/repos","events_url":"https://api.github.com/users/redowl/events{/privacy}","received_events_url":"https://api.github.com/users/redowl/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-30T18:26:41Z","updated_at":"2015-06-30T18:49:02Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch-hadoop/pulls/488","html_url":"https://github.com/elastic/elasticsearch-hadoop/pull/488","diff_url":"https://github.com/elastic/elasticsearch-hadoop/pull/488.diff","patch_url":"https://github.com/elastic/elasticsearch-hadoop/pull/488.patch"},"body":"See Issue: https://github.com/elastic/elasticsearch-hadoop/issues/487\r\n\r\nIn the class `org.elasticsearch.hadoop.rest.RestRepository`, if you call `close()` multiple times in a row (which happens occasionally in our libs because of chained close calls), every time after the first will \r\nthrow a NullPointerException if `requiresRefreshAfterBulk && executedBulkWrite` evaluates to true:\r\n\r\n### RestRepository.java (snippet)\r\n(Source here: See source here: \r\nhttps://github.com/elastic/elasticsearch-hadoop/blob/master/mr/src/main/java/org/elasticsearch/hadoop/rest/RestRepository.java#L255)\r\n```java\r\n\r\npublic void close() {\r\n    ...\r\n    if (requiresRefreshAfterBulk && executedBulkWrite) {\r\n        // refresh batch\r\n        client.refresh(resourceW); // THIS THROWS THE NPE BECAUSE \r\n                                   // IT GETS SET TO NULL BELOW\r\n\r\n        if (log.isDebugEnabled()) {\r\n            log.debug(String.format(\"Refreshing index [%s]\", resourceW));\r\n        }\r\n    }\r\n\r\n    if (client != null) {\r\n        client.close();\r\n        stats.aggregate(client.stats());\r\n        client = null; // THIS FIRES THE FIRST TIME THROUGH AND MAKES THE REST FAIL\r\n    }\r\n}\r\n```\r\n\r\nPopping the refresh logic into the `client != null` block seems like the most correct solution."},"comment":{"url":"https://api.github.com/repos/elastic/elasticsearch-hadoop/issues/comments/117299483","html_url":"https://github.com/elastic/elasticsearch-hadoop/pull/488#issuecomment-117299483","issue_url":"https://api.github.com/repos/elastic/elasticsearch-hadoop/issues/488","id":117299483,"user":{"login":"redowl","id":1513344,"avatar_url":"https://avatars.githubusercontent.com/u/1513344?v=3","gravatar_id":"","url":"https://api.github.com/users/redowl","html_url":"https://github.com/redowl","followers_url":"https://api.github.com/users/redowl/followers","following_url":"https://api.github.com/users/redowl/following{/other_user}","gists_url":"https://api.github.com/users/redowl/gists{/gist_id}","starred_url":"https://api.github.com/users/redowl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/redowl/subscriptions","organizations_url":"https://api.github.com/users/redowl/orgs","repos_url":"https://api.github.com/users/redowl/repos","events_url":"https://api.github.com/users/redowl/events{/privacy}","received_events_url":"https://api.github.com/users/redowl/received_events","type":"User","site_admin":false},"created_at":"2015-06-30T18:49:02Z","updated_at":"2015-06-30T18:49:02Z","body":"We've signed the Company CLA now\r\n\r\nCompany: RedOwl Analytics\r\nEmail: paul@redowlanalytics.com"}}