espertechinc / esper

Esper Complex Event Processing, Streaming SQL and Event Series Analysis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NPE when compiling from Map type property

0x006EA1E5 opened this issue · comments

In Esper 8.7.0 I get a NPE when running the following

        var compiler = EPCompilerProvider.getCompiler();

        var compilerArguments = new CompilerArguments();
        var compile = compiler.compile("@public create map schema TEST as (mapProp java.util.Map)", compilerArguments);

        compilerArguments.getPath().add(compile);
        compiler.compile("select * from TEST where mapProp.get('routeId') is not null", compilerArguments);

However this is fine if the type of mapProp is java.util.HashMap

It is also fine if add a ? to the end of the where like this: mapProp.get('routeId')? to mark it as a dynamic type.

  • Should it give a clearer error message than Unexpected error compiling statement / NPE?
  • If it fails for Map, should it also fail for HashMap?

Possibly related to #235

@icholy yes it's a similar stack trace

com.espertech.esper.compiler.client.EPCompileException: Unexpected error compiling statement: java.lang.NullPointerException:null [select * from TEST where mapProp.get('routeId') is not null]

	at com.espertech.esper.compiler.internal.util.CompilerHelperModuleProvider.compileToBytes(CompilerHelperModuleProvider.java:172)
	at com.espertech.esper.compiler.internal.util.CompilerHelperModuleProvider.compile(CompilerHelperModuleProvider.java:89)
	at com.espertech.esper.compiler.internal.util.EPCompilerImpl.compile(EPCompilerImpl.java:98)
	at com.ocado.flux.esper.state.EsterTest.name(EsterTest.java:24)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:688)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)
	at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:210)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:206)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:131)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:65)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:108)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:96)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:75)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:221)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: com.espertech.esper.compiler.client.EPCompileExceptionItem: Unexpected error compiling statement: java.lang.NullPointerException:null
	at com.espertech.esper.compiler.internal.util.CompilerHelperModuleProvider.compileToBytes(CompilerHelperModuleProvider.java:147)
	... 68 more
Caused by: com.espertech.esper.common.internal.compile.stage2.StatementSpecCompileException: Unexpected error compiling statement: java.lang.NullPointerException:null
	at com.espertech.esper.common.internal.compile.stage2.StatementRawCompiler.compile(StatementRawCompiler.java:179)
	at com.espertech.esper.compiler.internal.util.CompilerHelperStatementProvider.compileItem(CompilerHelperStatementProvider.java:162)
	at com.espertech.esper.compiler.internal.util.CompilerHelperModuleProvider.compileToBytes(CompilerHelperModuleProvider.java:127)
	... 68 more
Caused by: java.lang.NullPointerException
	at com.espertech.esper.common.internal.event.property.MappedProperty.getPropertyTypeMap(MappedProperty.java:125)
	at com.espertech.esper.common.internal.event.core.EventTypeUtility.getNestablePropertyType(EventTypeUtility.java:1004)
	at com.espertech.esper.common.internal.event.core.BaseNestableEventType.getPropertyEPType(BaseNestableEventType.java:140)
	at com.espertech.esper.common.internal.event.core.BaseNestableEventType.isProperty(BaseNestableEventType.java:185)
	at com.espertech.esper.common.internal.epl.streamtype.StreamTypeServiceImpl.findByPropertyName(StreamTypeServiceImpl.java:248)
	at com.espertech.esper.common.internal.epl.streamtype.StreamTypeServiceImpl.resolveByPropertyName(StreamTypeServiceImpl.java:158)
	at com.espertech.esper.common.internal.epl.expression.core.ExprIdentNodeUtil.getTypeFromStream(ExprIdentNodeUtil.java:73)
	at com.espertech.esper.common.internal.epl.expression.core.ExprIdentNodeImpl.validate(ExprIdentNodeImpl.java:200)
	at com.espertech.esper.common.internal.epl.expression.core.ExprNodeUtilityValidate.getValidatedSubtreeInternal(ExprNodeUtilityValidate.java:297)
	at com.espertech.esper.common.internal.epl.expression.core.ExprNodeUtilityValidate.getValidatedSubtreeInternal(ExprNodeUtilityValidate.java:292)
	at com.espertech.esper.common.internal.epl.expression.core.ExprNodeUtilityValidate.getValidatedSubtree(ExprNodeUtilityValidate.java:156)
	at com.espertech.esper.common.internal.compile.stage2.FilterSpecCompiler.validateAllowSubquery(FilterSpecCompiler.java:150)
	at com.espertech.esper.common.internal.compile.stage2.FilterSpecCompiler.makeFilterSpec(FilterSpecCompiler.java:58)
	at com.espertech.esper.common.internal.compile.stage2.StreamSpecCompiler.compileFilter(StreamSpecCompiler.java:129)
	at com.espertech.esper.common.internal.compile.stage2.StreamSpecCompiler.compile(StreamSpecCompiler.java:79)
	at com.espertech.esper.common.internal.compile.stage2.StatementRawCompiler.compile(StatementRawCompiler.java:164)
	... 70 more

In EventTypeUtility it does this:

        // If there is a map value in the map, return the Object value if this is a dynamic property
        if (nestedType instanceof EPTypeClass && ((EPTypeClass) nestedType).getType() == Map.class) {
            Property prop = PropertyParser.parseAndWalk(propertyNested, isRootedDynamic);
            return isRootedDynamic ? EPTypePremade.OBJECT.getEPType() : JavaClassHelper.getBoxedType(prop.getPropertyTypeMap(null, beanEventTypeFactory));   // we don't have a definition of the nested props

Note prop.getPropertyTypeMap(null, beanEventTypeFactory)

And the implementation for MappedProperty is

    public EPType getPropertyTypeMap(Map optionalMapPropTypes, BeanEventTypeFactory beanEventTypeFactory) {
        Object type = optionalMapPropTypes.get(this.getPropertyNameAtomic());

The next section in EventTypeUtility is

        } else if (nestedType instanceof Map) {
            Property prop = PropertyParser.parseAndWalk(propertyNested, isRootedDynamic);
            Map nestedTypes = (Map) nestedType;
            return isRootedDynamic ? EPTypePremade.OBJECT.getEPType() : JavaClassHelper.getBoxedType(prop.getPropertyTypeMap(nestedTypes, beanEventTypeFactory));

☝️ Here is passes nestedTypes, not null.

Provide the code that reproduce the issue please

@bernhardttom It was included at the start of the thread, but I can put it here again:

        var compiler = EPCompilerProvider.getCompiler();

        var compilerArguments = new CompilerArguments();
        var compile = compiler.compile("@public create map schema TEST as (mapProp java.util.Map)", compilerArguments);

        compilerArguments.getPath().add(compile);
        compiler.compile("select * from TEST where mapProp.get('routeId') is not null", compilerArguments);