New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hazelcast fails to start with java.lang.ClassCastException: class java.lang.Boolean cannot be cast to class java.lang.String #26310
Labels
Comments
Thanks for the report, @kgignatyev |
devOpsHazelcast
pushed a commit
that referenced
this issue
Apr 15, 2024
…on startup with non-`String` properties (#1359) `SystemPropertiesConfigParser#parse(Properties)` iterates through the supplied `properties`'s key/values, performing an unchecked cast to `String` for comparison. When not a `String`, a `ClassCastException` is thrown which [prevents the instance from starting](#26310). Changes: - Check the key/value are `String`s, discarding otherwise - Refactored `SystemPropertiesConfigParser#parse(Properties)` to use `mapMulti` over `map` + `filter` invocations - testing with 200 dummy keys shows a ~50% improvement in throughput and reduction in GC litter - other slightly faster approaches (e.g. a plain loop) ignored due to readability Fixes #26310 GitOrigin-RevId: d1a83a4f0b5382c89e17db3303e479cb4eb278a8
devOpsHazelcast
pushed a commit
that referenced
this issue
Apr 16, 2024
…rties` (#1366) `java.util.Properties` extends a `Map<Object, Object>`, which means the `put`/`putAll` etc have `Object` parameters - however [the Javadoc says](https://docs.oracle.com/javase/8/docs/api/java/util/Properties.html): > Because Properties inherits from Hashtable, the put and putAll methods can be applied to a Properties object. Their use is strongly discouraged as they allow the caller to insert entries whose keys or values are not Strings. The setProperty method should be used instead. [Flyway recently broke with this convention](flyway/flyway#3866), causing problems in: - [Hazelcast due to the unexpected types](#26310) - [Scala wrapper](flyway/flyway#3866 (comment)) [Flyway subsequently resolved this](flyway/flyway#3866 (comment)). The intent of this PR is to enhance the codebase to use type-safety to prevent these errors being introduced in future, rather than ensuring compliance with this convention. _Most_ uses of `Properties` in Hazelcast are already `String`s: - Changing the non-`String` types is out of scope - When working with `String`s, the more specific `setProperty`/`getProperty` should be used in preference to `put`/`putAll`/`get`, _where possible_ GitOrigin-RevId: 25ada108ca08e37af76338d00650780135cef24c
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
Hazelcast instance cannot be created, throws exception
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.hazelcast.core.HazelcastInstance]: Factory method 'hazelcastInstance' threw exception with message: class java.lang.Boolean cannot be cast to class java.lang.String (java.lang.Boolean and java.lang.String are in module java.base of loader 'bootstrap')
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:177) ~[spring-beans-6.1.5.jar:6.1.5]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:644) ~[spring-beans-6.1.5.jar:6.1.5]
... 79 common frames omitted
Caused by: java.lang.ClassCastException: class java.lang.Boolean cannot be cast to class java.lang.String (java.lang.Boolean and java.lang.String are in module java.base of loader 'bootstrap')
at com.hazelcast.internal.config.override.SystemPropertiesConfigParser.lambda$parse$0(SystemPropertiesConfigParser.java:49) ~[hazelcast-5.3.7.jar:5.3.7]
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) ~[na:na]
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133) ~[na:na]
This is cause by polyglot.engine.WarnInterpreterOnly property value, which is boolean but
hazelcast-5.3.6-sources.jar!/com/hazelcast/internal/config/override/SystemPropertiesConfigParser.java:49
code expects all values to be String-s
Expected behavior
Hazelcast instance starts even when system properties have non string properties
To Reproduce
Additional context
java -version
openjdk version "21.0.2" 2024-01-16 LTS
OpenJDK Runtime Environment Zulu21.32+17-CA (build 21.0.2+13-LTS)
OpenJDK 64-Bit Server VM Zulu21.32+17-CA (build 21.0.2+13-LTS, mixed mode, sharing)
uname -a
Darwin Konstantins-M1-MBP.local 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000 arm64
The text was updated successfully, but these errors were encountered: