This is an automated email from the ASF dual-hosted git repository. borinquenkid pushed a commit to branch test/document-datamapping-events in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit 7b5204bcc2998c073d5b826968abae621aaae908 Author: Walter Duque de Estrada <[email protected]> AuthorDate: Fri Aug 14 11:08:03 2026 -0500 Fix AutoTimestampEventListener IntelliJ warnings - supportsEventType is now null-safe, matching Spring 7's SmartApplicationListener.supportsEventType @Nullable contract - Parameterized every raw Class/List<Class> usage across the withoutLastUpdated/withoutDateCreated/withoutTimestamps overloads and their shared runWithDisabled helper - Replaced disabled.entityNames.removeAll(added) (a HashSet.removeAll of a List, which can fall into an O(n*m) path depending on relative collection sizes) with a direct per-element remove, guaranteeing O(1) removals regardless of size getTimestampProvider() was also flagged as unused but left as-is: it's the getter half of a real getter/setter bean-property pair (the setter is the intended extension point for injecting a custom TimestampProvider), not dead code. Full suite, jacoco, and codeStyle all clean. --- .../gorm/events/AutoTimestampEventListener.java | 29 +++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/events/AutoTimestampEventListener.java b/grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/events/AutoTimestampEventListener.java index 8ecf4e12bb..04ebaf8e31 100644 --- a/grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/events/AutoTimestampEventListener.java +++ b/grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/events/AutoTimestampEventListener.java @@ -29,6 +29,8 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; +import org.jspecify.annotations.NonNull; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext; @@ -124,9 +126,8 @@ public class AutoTimestampEventListener extends AbstractPersistenceEventListener } } - public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) { - return PreInsertEvent.class.isAssignableFrom(eventType) || - PreUpdateEvent.class.isAssignableFrom(eventType); + public boolean supportsEventType(@NonNull Class<? extends ApplicationEvent> eventType) { + return PreInsertEvent.class.isAssignableFrom(eventType) || PreUpdateEvent.class.isAssignableFrom(eventType); } public boolean beforeInsert(PersistentEntity entity, EntityAccess ea) { @@ -341,13 +342,13 @@ public class AutoTimestampEventListener extends AbstractPersistenceEventListener } } - private static void runWithDisabled(final ThreadLocal<DisabledTimestamps> disabledTimestamps, final List<Class> classes, final Runnable runnable) { + private static void runWithDisabled(final ThreadLocal<DisabledTimestamps> disabledTimestamps, final List<Class<?>> classes, final Runnable runnable) { // only the names this scope newly disables may be re-enabled on exit; a name already // disabled by an enclosing scope on this thread must survive this scope's finally List<String> added = new ArrayList<>(classes.size()); DisabledTimestamps disabled = getOrCreateDisabled(disabledTimestamps); try { - for (Class clazz : classes) { + for (Class<?> clazz : classes) { String entityName = clazz.getName(); if (disabled.entityNames.add(entityName)) { added.add(entityName); @@ -355,7 +356,7 @@ public class AutoTimestampEventListener extends AbstractPersistenceEventListener } runnable.run(); } finally { - disabled.entityNames.removeAll(added); + added.forEach(disabled.entityNames::remove); removeIfEmpty(disabledTimestamps, disabled); } } @@ -379,7 +380,7 @@ public class AutoTimestampEventListener extends AbstractPersistenceEventListener * @param classes Which classes to disable the last updated processing for * @param runnable The code to execute while the last updated listener is disabled */ - public void withoutLastUpdated(final List<Class> classes, final Runnable runnable) { + public void withoutLastUpdated(final List<Class<?>> classes, final Runnable runnable) { runWithDisabled(disabledLastUpdated, classes, runnable); } @@ -391,8 +392,8 @@ public class AutoTimestampEventListener extends AbstractPersistenceEventListener * @param clazz Which class to disable the last updated processing for * @param runnable The code to execute while the last updated listener is disabled */ - public void withoutLastUpdated(final Class clazz, final Runnable runnable) { - ArrayList<Class> list = new ArrayList<>(1); + public void withoutLastUpdated(final Class<?> clazz, final Runnable runnable) { + ArrayList<Class<?>> list = new ArrayList<>(1); list.add(clazz); withoutLastUpdated(list, runnable); } @@ -416,7 +417,7 @@ public class AutoTimestampEventListener extends AbstractPersistenceEventListener * @param classes Which classes to disable the date created processing for * @param runnable The code to execute while the date created listener is disabled */ - public void withoutDateCreated(final List<Class> classes, final Runnable runnable) { + public void withoutDateCreated(final List<Class<?>> classes, final Runnable runnable) { runWithDisabled(disabledDateCreated, classes, runnable); } @@ -428,8 +429,8 @@ public class AutoTimestampEventListener extends AbstractPersistenceEventListener * @param clazz Which class to disable the date created processing for * @param runnable The code to execute while the date created listener is disabled */ - public void withoutDateCreated(final Class clazz, final Runnable runnable) { - ArrayList<Class> list = new ArrayList<>(1); + public void withoutDateCreated(final Class<?> clazz, final Runnable runnable) { + ArrayList<Class<?>> list = new ArrayList<>(1); list.add(clazz); withoutDateCreated(list, runnable); } @@ -453,7 +454,7 @@ public class AutoTimestampEventListener extends AbstractPersistenceEventListener * @param classes Which classes to disable the timestamp processing for * @param runnable The code to execute while the timestamp listeners are disabled */ - public void withoutTimestamps(final List<Class> classes, final Runnable runnable) { + public void withoutTimestamps(final List<Class<?>> classes, final Runnable runnable) { withoutDateCreated(classes, () -> withoutLastUpdated(classes, runnable)); } @@ -465,7 +466,7 @@ public class AutoTimestampEventListener extends AbstractPersistenceEventListener * @param clazz Which class to disable the timestamp processing for * @param runnable The code to execute while the timestamp listeners are disabled */ - public void withoutTimestamps(final Class clazz, final Runnable runnable) { + public void withoutTimestamps(final Class<?> clazz, final Runnable runnable) { withoutDateCreated(clazz, () -> withoutLastUpdated(clazz, runnable)); }
