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

**URL:** https://discuss.elastic.co/t/using-numbers-in-conditionals-leads-to-fatal-java-lang-classcastexception-class-org-jruby-rubyfixnum-cannot-be-cast-to-class-java-lang-long/231962
**Category:** Logstash
**Created:** [May 11, 2020, 9:02am UTC](https://discuss.elastic.co/t/using-numbers-in-conditionals-leads-to-fatal-java-lang-classcastexception-class-org-jruby-rubyfixnum-cannot-be-cast-to-class-java-lang-long/231962 "2020-05-11T09:02:38Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![DavidFineboym](https://avatars.discourse-cdn.com/v4/letter/d/a9a28c/32.png) [@DavidFineboym](https://discuss.elastic.co/u/DavidFineboym)
#### Post date: [May 11, 2020, 9:02am UTC](https://discuss.elastic.co/t/using-numbers-in-conditionals-leads-to-fatal-java-lang-classcastexception-class-org-jruby-rubyfixnum-cannot-be-cast-to-class-java-lang-long/231962/1 "2020-05-11T09:02:38Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ptamba](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@ptamba](https://discuss.elastic.co/u/ptamba)
#### Post date: [May 11, 2020, 1:13pm UTC](https://discuss.elastic.co/t/using-numbers-in-conditionals-leads-to-fatal-java-lang-classcastexception-class-org-jruby-rubyfixnum-cannot-be-cast-to-class-java-lang-long/231962/2 "2020-05-11T13:13:57Z")

</div>

wrap the values in double quotes as describes in the [docs](https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html)

---

<div class="post-metadata">

### Author: ![DavidFineboym](https://avatars.discourse-cdn.com/v4/letter/d/a9a28c/32.png) [@DavidFineboym](https://discuss.elastic.co/u/DavidFineboym)
#### Post date: [May 17, 2020, 1:52pm UTC](https://discuss.elastic.co/t/using-numbers-in-conditionals-leads-to-fatal-java-lang-classcastexception-class-org-jruby-rubyfixnum-cannot-be-cast-to-class-java-lang-long/231962/3 "2020-05-17T13:52:31Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![DavidFineboym](https://avatars.discourse-cdn.com/v4/letter/d/a9a28c/32.png) [@DavidFineboym](https://discuss.elastic.co/u/DavidFineboym)
#### Post date: [May 17, 2020, 2:00pm UTC](https://discuss.elastic.co/t/using-numbers-in-conditionals-leads-to-fatal-java-lang-classcastexception-class-org-jruby-rubyfixnum-cannot-be-cast-to-class-java-lang-long/231962/4 "2020-05-17T14:00:06Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [June 14, 2020, 2:00pm UTC](https://discuss.elastic.co/t/using-numbers-in-conditionals-leads-to-fatal-java-lang-classcastexception-class-org-jruby-rubyfixnum-cannot-be-cast-to-class-java-lang-long/231962/5 "2020-06-14T14:00:14Z")

</div>

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