From dfb7165b76d609d62bf27817faa15459126b2b44 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Mon, 30 Sep 2024 19:36:32 +0200 Subject: [PATCH] Conditionally instantiates java.sql.Date --- CHANGELOG.md | 4 +++ .../reflection/JavaApiPrefabValues.java | 29 +++++++++++-------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa797a769..947a19b3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Instantiates `java.sql.Date` only when available, so EqualsVerifier no longer throws `NoClassDefFoundError` when it's not available. ([Issue 746](https://github.com/jqno/equalsverifier/issues/746)) + ## [3.17] - 2024-09-24 ### Added diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/JavaApiPrefabValues.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/JavaApiPrefabValues.java index 0105c4b26..e1db1d3e3 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/JavaApiPrefabValues.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/JavaApiPrefabValues.java @@ -327,23 +327,28 @@ private void addDateTimeClasses() { private void addUncommonClasses() { addFactory(ThreadLocal.class, simple(a -> ThreadLocal.withInitial(() -> a), null)); + // Constructing java.sql.* classes reflectively, because they reside in a different module + // which causes trouble when running EqualsVerifier on the modulepath. + ConditionalInstantiator sqlDate = new ConditionalInstantiator("java.sql.Date"); + ConditionalInstantiator sqlTime = new ConditionalInstantiator("java.sql.Time"); + ConditionalInstantiator sqlTimestamp = new ConditionalInstantiator("java.sql.Timestamp"); addValues( - java.sql.Date.class, - new java.sql.Date(1337), - new java.sql.Date(42), - new java.sql.Date(1337) + sqlDate.resolve(), + sqlDate.instantiate(classes(long.class), objects(1337)), + sqlDate.instantiate(classes(long.class), objects(42)), + sqlDate.instantiate(classes(long.class), objects(1337)) ); addValues( - java.sql.Time.class, - new java.sql.Time(1337), - new java.sql.Time(42), - new java.sql.Time(1337) + sqlTime.resolve(), + sqlTime.instantiate(classes(long.class), objects(1337)), + sqlTime.instantiate(classes(long.class), objects(42)), + sqlTime.instantiate(classes(long.class), objects(1337)) ); addValues( - java.sql.Timestamp.class, - new java.sql.Timestamp(1337), - new java.sql.Timestamp(42), - new java.sql.Timestamp(1337) + sqlTimestamp.resolve(), + sqlTimestamp.instantiate(classes(long.class), objects(1337)), + sqlTimestamp.instantiate(classes(long.class), objects(42)), + sqlTimestamp.instantiate(classes(long.class), objects(1337)) ); addValues(EventObject.class, new EventObject(1), new EventObject(2), new EventObject(1));