{"action":"closed","issue":{"url":"https://api.github.com/repos/espertechinc/esper/issues/33","repository_url":"https://api.github.com/repos/espertechinc/esper","labels_url":"https://api.github.com/repos/espertechinc/esper/issues/33/labels{/name}","comments_url":"https://api.github.com/repos/espertechinc/esper/issues/33/comments","events_url":"https://api.github.com/repos/espertechinc/esper/issues/33/events","html_url":"https://github.com/espertechinc/esper/issues/33","id":124250521,"number":33,"title":"NullPointerException with non-aggregated `having` clause and addListenerWithReplay","user":{"login":"mstrobel","id":993245,"avatar_url":"https://avatars.githubusercontent.com/u/993245?v=3","gravatar_id":"","url":"https://api.github.com/users/mstrobel","html_url":"https://github.com/mstrobel","followers_url":"https://api.github.com/users/mstrobel/followers","following_url":"https://api.github.com/users/mstrobel/following{/other_user}","gists_url":"https://api.github.com/users/mstrobel/gists{/gist_id}","starred_url":"https://api.github.com/users/mstrobel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mstrobel/subscriptions","organizations_url":"https://api.github.com/users/mstrobel/orgs","repos_url":"https://api.github.com/users/mstrobel/repos","events_url":"https://api.github.com/users/mstrobel/events{/privacy}","received_events_url":"https://api.github.com/users/mstrobel/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-29T18:31:00Z","updated_at":"2016-03-11T17:20:44Z","closed_at":"2016-03-11T17:20:44Z","body":"The following example illustrates a `NullPointerException` in `ResultSetProcessorSimpleTransform` when a query over a named window includes a simple `having` clause that initially yields no results:\r\n\r\n```java\r\nimport com.espertech.esper.client.*;\r\n\r\nimport java.util.Arrays;\r\n\r\npublic class EsperBug {\r\n    static class TestEvent {\r\n        private final String _origin;\r\n        private final int _size;\r\n\r\n        public TestEvent(final String origin, final int size) {\r\n            _origin = origin;\r\n            _size = size;\r\n        }\r\n\r\n        public String getOrigin() {\r\n            return _origin;\r\n        }\r\n\r\n        public int getSize() {\r\n            return _size;\r\n        }\r\n    }\r\n\r\n    public static void main(final String... args) throws Throwable {\r\n        final EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider();\r\n        final EPRuntime runtime = epService.getEPRuntime();\r\n        final EPAdministrator administrator = epService.getEPAdministrator();\r\n\r\n        administrator.getConfiguration().addEventType(\"TestEvent\", TestEvent.class);\r\n\r\n        administrator.getDeploymentAdmin().parseDeploy(\r\n            \"create window TestEvents.win:keepall() as TestEvent;\\n\" +\r\n            \"insert into TestEvents select * from TestEvent;\\n\");\r\n\r\n        runtime.sendEvent(new TestEvent(\"ORIGIN\", 1));\r\n        runtime.sendEvent(new TestEvent(\"ORIGIN\", 2));\r\n\r\n        final EPStatement epl = administrator.createEPL(\r\n            \"select origin, size from TestEvents\\n\" +\r\n//            \"group by origin\\n\" +\r\n            \"having size > 4000\"\r\n        );\r\n\r\n        epl.start();\r\n\r\n        epl.addListenerWithReplay(\r\n            new UpdateListener() {\r\n                @Override\r\n                public void update(final EventBean[] newEvents, final EventBean[] oldEvents) {\r\n                    System.out.println(Arrays.toString(newEvents));\r\n                }\r\n            }\r\n        );\r\n    }\r\n}\r\n```\r\nThe error stack trace is as follows:\r\n\r\n    Exception in thread \"main\" java.lang.NullPointerException\r\n        at com.espertech.esper.epl.core.ResultSetProcessorSimpleTransform.transform(ResultSetProcessorSimpleTransform.java:36)\r\n        at com.espertech.esper.collection.TransformEventIterator.next(TransformEventIterator.java:48)\r\n        at com.espertech.esper.collection.TransformEventIterator.next(TransformEventIterator.java:20)\r\n        at com.espertech.esper.core.service.EPStatementImpl.addListenerWithReplay(EPStatementImpl.java:366)\r\n        at EsperBug.main(EsperBug.java:46)\r\n        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\r\n        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n        at java.lang.reflect.Method.invoke(Method.java:497)\r\n        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)\r\n\r\nThe exception site, `ResultSetProcessorSimpleTransform::transform`, attempts to access an element in an array of `EventBean[]` that happens to be `null` in this case:\r\n\r\n    public EventBean transform(EventBean theEvent)\r\n    {\r\n        newData[0] = theEvent;\r\n        UniformPair<EventBean[]> pair = resultSetProcessor.processViewResult(newData, null, true);\r\n        return pair.getFirst()[0];\r\n    }\r\n\r\nAdding a `group by` clause circumvents the exception, as can be seen by uncommenting the second line of the query."}}