{"action":"created","issue":{"url":"https://api.github.com/repos/larsga/Duke/issues/211","labels_url":"https://api.github.com/repos/larsga/Duke/issues/211/labels{/name}","comments_url":"https://api.github.com/repos/larsga/Duke/issues/211/comments","events_url":"https://api.github.com/repos/larsga/Duke/issues/211/events","html_url":"https://github.com/larsga/Duke/issues/211","id":109290632,"number":211,"title":"Null value returned from TrimCleaner","user":{"login":"iDmple","id":5065505,"avatar_url":"https://avatars.githubusercontent.com/u/5065505?v=3","gravatar_id":"","url":"https://api.github.com/users/iDmple","html_url":"https://github.com/iDmple","followers_url":"https://api.github.com/users/iDmple/followers","following_url":"https://api.github.com/users/iDmple/following{/other_user}","gists_url":"https://api.github.com/users/iDmple/gists{/gist_id}","starred_url":"https://api.github.com/users/iDmple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iDmple/subscriptions","organizations_url":"https://api.github.com/users/iDmple/orgs","repos_url":"https://api.github.com/users/iDmple/repos","events_url":"https://api.github.com/users/iDmple/events{/privacy}","received_events_url":"https://api.github.com/users/iDmple/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-10-01T12:37:51Z","updated_at":"2015-10-01T13:09:45Z","closed_at":null,"body":"Hi Lars,\r\n\r\nI'm using TrimCleaner from Yann's plugin for entity resolution.\r\n\r\npublic class TrimCleaner implements Cleaner {\r\n\r\n  public String clean(String value) {\r\n    value = value.trim();\r\n    if (value.equals(\"\"))\r\n      return null;\r\n    return value;\r\n  }\r\n  \r\n}\r\n\r\nSome of my input strings are emtpy \"\", thus TrimCleaner returns null which provokes a NullPointerException. Why not return \"\" when an empty string is trimmed?\r\n\r\nHow can I avoid this problem?\r\n\r\nBest regards"},"comment":{"url":"https://api.github.com/repos/larsga/Duke/issues/comments/144721866","html_url":"https://github.com/larsga/Duke/issues/211#issuecomment-144721866","issue_url":"https://api.github.com/repos/larsga/Duke/issues/211","id":144721866,"user":{"login":"iDmple","id":5065505,"avatar_url":"https://avatars.githubusercontent.com/u/5065505?v=3","gravatar_id":"","url":"https://api.github.com/users/iDmple","html_url":"https://github.com/iDmple","followers_url":"https://api.github.com/users/iDmple/followers","following_url":"https://api.github.com/users/iDmple/following{/other_user}","gists_url":"https://api.github.com/users/iDmple/gists{/gist_id}","starred_url":"https://api.github.com/users/iDmple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iDmple/subscriptions","organizations_url":"https://api.github.com/users/iDmple/orgs","repos_url":"https://api.github.com/users/iDmple/repos","events_url":"https://api.github.com/users/iDmple/events{/privacy}","received_events_url":"https://api.github.com/users/iDmple/received_events","type":"User","site_admin":false},"created_at":"2015-10-01T13:09:45Z","updated_at":"2015-10-01T13:09:45Z","body":"OK, in the meantime I have found the problem. I think it would be great to throw an exception or something to avoid that the cleaner is called.\r\n\r\nHere is the code that fails:\r\n\r\n   private void readFields(List<Map<String, Object>> fields, Map<String, Collection<String>> props) {\r\n        for (Map<String, Object> value : fields) {\r\n            String field = (String) value.get(\"field\");\r\n            String fieldValue = (String) value.get(\"value\");\r\n            for (Cleaner cl : (ArrayList<Cleaner>) entityParams.get(field).get(CLEANERS)) {\r\n                fieldValue = cl.clean(fieldValue);\r\n            }\r\n            props.put(field, Collections.singleton(fieldValue));\r\n        }\r\n    }\r\n\r\nI replaced it with:\r\n\r\n    private void readFields(List<Map<String, Object>> fields, Map<String, Collection<String>> props) {\r\n        for (Map<String, Object> value : fields) {\r\n            String field = (String) value.get(\"field\");\r\n            String fieldValue = value.get(\"value\").toString();\r\n            for (Cleaner cl : (ArrayList<Cleaner>) entityParams.get(field).get(CLEANERS)) {\r\n                if(fieldValue!=null && !fieldValue.equals(\"\")) {\r\n                    fieldValue = cl.clean(fieldValue);\r\n                }\r\n            }\r\n            props.put(field, Collections.singleton(fieldValue));\r\n        }\r\n    }\r\n\r\nI made lots of other changed in the plugin because it fails from everywhere with NullPointerException and cast problems. Will do a pull request when my project is ready and I find no more errors.\r\n\r\nI think that duke API should be used and not call internal functions like this. It would be better to have elasticsearch as a datasource."}}