mongock / mongock

Lightweight Java based migration tool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ChangeUnits containing Unnamed Variables (JEP443) are not found by Mongock.

florian-gehring opened this issue · comments

Description

ChangeUnits that contain unnamed variables (the "_" placeholder) anywhere in them, are not found or executed by Mongock. Replacing the placeholder with a named (and unused) variable will result in the ChangeUnit being found again.

PRIORITY

NORMAL / Not Sure

Version and environment

Mongock

  • Mongock version: COMMUNITY version[5.3.4]
  • Modules involved: springboot, MongoDB
  • How Mongock is used: annotation approach

Environment

  • Framework and libraries versions. Especially those that affect directly to Mongock:
    • Spring Boot Version: 3.1.4
  • Infrastructure: Kubernetes, Docker
  • Importing the mongock-bom dependency
  • Java Language Level 21 (Preview Features Enabled)

Steps to Reproduce

  1. Create a ChangeUnit that uses a Lambda Function with an unnamed variable, e.g. .map(document -> (AggregationOperation) _ -> document) somewhere in a stream.
  2. Start the application as normal

Behaviour

Expected behavior: The ChangeUnit gets executed
Actual behavior: Mongock does not find the ChangeUnit.

How often the bug happens: Every time.

Additional context

The reflection library Mongock uses apparently can't return classes containing these features.
In ChangeLogServiceBase.java:163 the ChangeUnit class is present in the Object constructed by new Reflections(changeLogsBasePackageList) but the getTypesAnnotatedWith(ChangeUnit.class) returns an empty list, if the "_"-Placeholder is used anywhere in the file.

We recently upgraded to java 21 with preview features enabled too and could not make sense of some changeunits not being picked up by mongock until reading your issue. We confirmed this issue with our codebase!

@florian-gehring we'll take a look at this, but for the time being, as workaround, is it enough if you don't use "_"?

@spalberg this is not the same problem. Please see this issue.

@dieppa it's exactly the same issue as described here. When a changeunit uses the unnamed variable feature it is completely overlooked by mongock when picking up the changeunits via reflection. Not using the unnamed variable fixes that.

I am not familiar with that feature. We'll look at it as soon as possible.

In the meanwhile, yiu are welcome to raise a PR if you feel so.

@dieppa Hello, thank you for your comment. Yes, we've commited to not using "_" so the workaround is perfectly fine. This issue is less of a "PLEASE FIX" and more of a "Just FYI". It's a preview feature after all.

Thanks @florian-gehring for letting us know. We have a lot of new exciting things for the upcoming major release, hopefully we can add these nicr to have to it, so we are more up to date with modern java featured