Skip to content
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

ClassCastException #3866

Closed
BusyByte opened this issue Apr 5, 2024 · 6 comments
Closed

ClassCastException #3866

BusyByte opened this issue Apr 5, 2024 · 6 comments

Comments

@BusyByte
Copy link

BusyByte commented Apr 5, 2024

Which version and edition of Flyway are you using?

Started to see ClassCastException in sbt like in this gist
on our build server in drone

Rolled back from 10.11.0 to 10.10.0 of flyway and it resolved the issue.

Locally on my macbook it was working fine on the new version.

If this is not the latest version, can you reproduce the issue with the latest one as well? (Many bugs are fixed in newer releases and upgrading will often resolve the issue)
Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin)

maven dep from sbt

   val flywayV = "10.11.0"
   val flywayCore = "org.flywaydb" % "flyway-core" % flywayV
   val flywayPostgres = "org.flywaydb" % "flyway-database-postgresql" % flywayV
Which database are you using? (Type & version)

postgres 15.5 container

Which operating system are you using?

amazoncorretto 17 container

What did you do? (Please include the content causing the issue, any relevant configuration settings, the SQL statement(s) that failed (if any), and the command you ran)
What did you expect to see?
What did you see instead?
@arturaz
Copy link

arturaz commented Apr 5, 2024

The issue stems from the fact that Scala wrapper expects System.getProperties to be a Map[String, String]:

  case class JPropertiesWrapper(underlying: ju.Properties) extends mutable.AbstractMap[String, String]
            with mutable.Map[String, String]
            with mutable.MapLike[String, String, JPropertiesWrapper] {
    def iterator: Iterator[(String, String)] = new AbstractIterator[(String, String)] {
      val ui = underlying.entrySet.iterator
      def hasNext = ui.hasNext
      def next() = {
        val e = ui.next()
        (e.getKey.asInstanceOf[String], e.getValue.asInstanceOf[String])
      }
    }
}

(as it should be according to https://stackoverflow.com/questions/873510/why-does-java-util-properties-implement-mapobject-object-and-not-mapstring-st), while something puts a Boolean in the untyped Hashtable.

Given that changing the Flyway version rectifies the issue we believe that something is Flyway.

@amumurst
Copy link

amumurst commented Apr 5, 2024

Could it be this?
00db8d5#diff-79abf6b6049fba7bfa35d38f11d573e97773eaa9518250b82f1cddb246dd17b2R49

@arturaz
Copy link

arturaz commented Apr 7, 2024

Could it be this? 00db8d5#diff-79abf6b6049fba7bfa35d38f11d573e97773eaa9518250b82f1cddb246dd17b2R49

Seems likely, it should be systemProperties.put("polyglot.engine.WarnInterpreterOnly", "false");.

@pzygielo
Copy link

pzygielo commented Apr 7, 2024

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.

@JasonLuo-Redgate
Copy link

Hi @arturaz @amumurst @pzygielo , many thanks for raising this bug.
We will look into it.

@JasonLuo-Redgate
Copy link

This has been fixed and will be included in the next release of Flyway.

lenguyenthanh added a commit to lenguyenthanh/fide that referenced this issue Apr 11, 2024
lenguyenthanh added a commit to lenguyenthanh/fide that referenced this issue Apr 11, 2024
lenguyenthanh added a commit to lenguyenthanh/fide that referenced this issue Apr 11, 2024
devOpsHazelcast pushed a commit to hazelcast/hazelcast 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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants