No check rejects @SoftDelete(strategy = TIMESTAMP), which later fails with NullPointerException

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: Model
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      Nothing in the extension checks for @SoftDelete. A TIMESTAMP strategy therefore survives
      metadata building and fails much later, while the SessionFactory pre-generates mutation statements:
      the strategy produces a ColumnWriteFragment whose fragment is null, and
      AbstractMqlTranslator.visitColumnWriteFragment passes it to a regex matcher.

      Reproducer

      @Entity @Table(name = "items")
      @SoftDelete(strategy = SoftDeleteType.TIMESTAMP)
      static class ItemSoftDeletedByTimestamp {
          @Id int id;
      }
      
      java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.length()" because "this.text" is null
        at java.base/java.util.regex.Pattern.matcher(Pattern.java:1145)
        at com.mongodb.hibernate.internal.translate.AbstractMqlTranslator.visitColumnWriteFragment(AbstractMqlTranslator.java:406)
      

      Proposed fix

      Decide whether the ACTIVE and DELETED strategies are supported, then add a boot-time rule in
      MongoAdditionalMappingContributor that rejects the strategies that are not, so the failure lands
      at boot with a message naming the annotation.

      The zero-parameter branch of visitColumnWriteFragment already throws
      FeatureNotSupportedException for a fragment it cannot parse. Extending that branch to cover a
      null fragment is worth doing regardless, as a backstop for any other source of a null fragment.

      Acceptance

      The mapping is rejected with FeatureNotSupportedException whose message names @SoftDelete and
      the offending strategy, and the supported strategies, if any, keep working.

            Assignee:
            Unassigned
            Reporter:
            Jeffrey Yemin
            None
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: