Using numbers in conditionals leads to fatal "java.lang.ClassCastException: class org.jruby.RubyFixnum cannot be cast to class java.lang.Long"

Hi,
I'm having trouble with conditional statements that include numbers in them in Logstash 7.6. The same pipeline configuration worked well in Logstash 6.8. I'm using Windows Server 2019 Datacenter, version 1809, and I have tried both Java 11 and 14 from official Oracle distributions, the result is the same.
I convert two fields to integers like so:

filter {
      mutate {
        convert => {
          " someField" => "integer"
          " someOtherField" => "integer"
        }
      }
    }

and then I use a conditional statement like this:

if [someField] == 5 and [someOtherField] < 45 {

}

At runtime, when Logstash processes an event that reaches that "if" statement, I get the following fatal exception and Logstash terminates:

[2020-05-11T06:40:36,152][ERROR][org.logstash.execution.WorkerLoop][mypipeline] Exception in pipelineworker, the pipeline stopped processing new events, please check your filter configuration and restart Logstash.
java.lang.ClassCastException: class org.jruby.RubyFixnum cannot be cast to class java.lang.Long (org.jruby.RubyFixnum is in unnamed module of loader 'app'; java.lang.Long is in module java.base of loader 'bootstrap')
	at java.lang.Long.compareTo(Long.java:65) ~[?:?]
	at org.logstash.config.ir.compiler.EventCondition$Compiler.compare(EventCondition.java:431) ~[logstash-core.jar:?]
	at org.logstash.config.ir.compiler.EventCondition$Compiler.lambda$compareFieldToConstant$11(EventCondition.java:424) ~[logstash-core.jar:?]
	at org.logstash.config.ir.compiler.EventCondition$Compiler.lambda$booleanCondition$4(EventCondition.java:142) ~[logstash-core.jar:?]
	at org.logstash.config.ir.compiler.EventCondition$Compiler.lambda$booleanCondition$4(EventCondition.java:142) ~[logstash-core.jar:?]
	at org.logstash.config.ir.compiler.Utils.filterEvents(Utils.java:27) ~[logstash-core.jar:?]
	at org.logstash.generated.CompiledDataset109.compute(Unknown Source) ~[?:?]
	at org.logstash.generated.CompiledDataset110.compute(Unknown Source) ~[?:?]
	at org.logstash.generated.CompiledDataset111.compute(Unknown Source) ~[?:?]
	at org.logstash.generated.CompiledDataset112.compute(Unknown Source) ~[?:?]
	at org.logstash.generated.CompiledDataset113.compute(Unknown Source) ~[?:?]
	at org.logstash.generated.CompiledDataset114.compute(Unknown Source) ~[?:?]
	at org.logstash.generated.CompiledDataset115.compute(Unknown Source) ~[?:?]
	at org.logstash.generated.CompiledDataset116.compute(Unknown Source) ~[?:?]
	at org.logstash.generated.CompiledDataset117.compute(Unknown Source) ~[?:?]
	at org.logstash.generated.CompiledDataset118.compute(Unknown Source) ~[?:?]
	at org.logstash.generated.CompiledDataset122.compute(Unknown Source) ~[?:?]
	at org.logstash.generated.CompiledDataset123.compute(Unknown Source) ~[?:?]
	at org.logstash.generated.CompiledDataset124.compute(Unknown Source) ~[?:?]
	at org.logstash.generated.CompiledDataset125.compute(Unknown Source) ~[?:?]
	at org.logstash.generated.CompiledDataset126.compute(Unknown Source) ~[?:?]
	at org.logstash.execution.WorkerLoop.run(WorkerLoop.java:64) [logstash-core.jar:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:564) ~[?:?]
	at org.jruby.javasupport.JavaMethod.invokeDirectWithExceptionHandling(JavaMethod.java:441) [jruby-complete-9.2.9.0.jar:?]
	at org.jruby.javasupport.JavaMethod.invokeDirect(JavaMethod.java:305) [jruby-complete-9.2.9.0.jar:?]
	at org.jruby.java.invokers.InstanceMethodInvoker.call(InstanceMethodInvoker.java:32) [jruby-complete-9.2.9.0.jar:?]
	at F_3a_.logstash_minus_7_dot_6_dot_2.logstash_minus_core.lib.logstash.java_pipeline.RUBY$block$start_workers$5(F:/logstash-7.6.2/logstash-core/lib/logstash/java_pipeline.rb:262) [jruby-complete-9.2.9.0.jar:?]
	at org.jruby.runtime.CompiledIRBlockBody.callDirect(CompiledIRBlockBody.java:136) [jruby-complete-9.2.9.0.jar:?]
	at org.jruby.runtime.IRBlockBody.call(IRBlockBody.java:77) [jruby-complete-9.2.9.0.jar:?]
	at org.jruby.runtime.IRBlockBody.call(IRBlockBody.java:71) [jruby-complete-9.2.9.0.jar:?]
	at org.jruby.runtime.Block.call(Block.java:125) [jruby-complete-9.2.9.0.jar:?]
	at org.jruby.RubyProc.call(RubyProc.java:274) [jruby-complete-9.2.9.0.jar:?]
	at org.jruby.internal.runtime.RubyRunnable.run(RubyRunnable.java:105) [jruby-complete-9.2.9.0.jar:?]
	at java.lang.Thread.run(Thread.java:832) [?:?]

[2020-05-11T06:40:36,417][FATAL][logstash.runner ] An unexpected error occurred! {:error=>java.lang.IllegalStateException: java.lang.ClassCastException: class org.jruby.RubyFixnum cannot be cast to class java.lang.Long (org.jruby.RubyFixnum is in unnamed module of loader 'app'; java.lang.Long is in module java.base of loader 'bootstrap'), :backtrace=>["org.logstash.execution.WorkerLoop.run(org/logstash/execution/WorkerLoop.java:85)", "jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)", "jdk.internal.reflect.NativeMethodAccessorImpl.invoke(jdk/internal/reflect/NativeMethodAccessorImpl.java:62)", "jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(jdk/internal/reflect/DelegatingMethodAccessorImpl.java:43)", "java.lang.reflect.Method.invoke(java/lang/reflect/Method.java:564)", "org.jruby.javasupport.JavaMethod.invokeDirectWithExceptionHandling(org/jruby/javasupport/JavaMethod.java:441)", "org.jruby.javasupport.JavaMethod.invokeDirect(org/jruby/javasupport/JavaMethod.java:305)", "F_3a_.logstash_minus_7_dot_6_dot_2.logstash_minus_core.lib.logstash.java_pipeline.start_workers(F:/logstash-7.6.2/logstash-core/lib/logstash/java_pipeline.rb:262)", "org.jruby.RubyProc.call(org/jruby/RubyProc.java:274)", "java.lang.Thread.run(java/lang/Thread.java:832)"]}

Can somebody please explain what is happening and how to solve this?
Thank you in advance.

wrap the values in double quotes as describes in the docs

Thank you for the effort, but in conditional statements if your intention is to perform number comparison and not string comparison, you should not wrap numbers in quotes and it's not written in the official documentation.

Now I understand the problem:

mutate {
        convert => {
          " someField" => "integer"
          " someOtherField" => "integer"
        }
      }

"mutate convert to integer" has to be in the same pipeline together with the conditional statement. I'm using pipeline-to-pipeline communication with JSON codec in "input" and "mutate convert to integer" was in pipeline upstream of the conditional statement.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.