fix(error): guard org.springframework.dao instanceof checks behind a classpath flag#14
Open
casc84ab wants to merge 1 commit into
Open
fix(error): guard org.springframework.dao instanceof checks behind a classpath flag#14casc84ab wants to merge 1 commit into
casc84ab wants to merge 1 commit into
Conversation
…classpath flag ExceptionMetadataAspect runs for every exception and used hard 'instanceof org.springframework.dao.DataIntegrityViolationException/QueryTimeoutException' checks. Those classes ship with spring-tx (pulled transitively by spring-data), which fireflyframework-web declares as optional, so data-less services (e.g. reactive BFFs) can run without it. There, the instanceof triggered a NoClassDefFoundError while building exception metadata, breaking the reactive error path (downstream errors surfaced as hangs/timeouts instead of clean 5xx). Gate both checks with a static SPRING_DAO_PRESENT flag (ClassUtils.isPresent). The && short-circuits the instanceof when the classes are absent, avoiding class resolution. When present (services with a database) the instanceof runs unchanged, still matching the full subclass hierarchy (e.g. DuplicateKeyException), so existing behavior is preserved. The converters that reference these types are already @ConditionalOnClass; this aligns the always-on aspect with that defensive pattern.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ExceptionMetadataAspect(@Aspect @Component @Order(1), always registered) runs for every exception via@AroundonExceptionConverterService.convertException. It used hard checks:Those classes ship with spring-tx (pulled transitively by spring-data).
fireflyframework-webdeclaresspring-data-commonsas optional, so data-less services (e.g. reactive BFFs without a DB) run without spring-tx on the classpath. There, theinstanceofforces class resolution at runtime and throwsNoClassDefFoundError: org/springframework/dao/DataIntegrityViolationExceptionwhile building exception metadata — breaking the reactive error path: downstream errors surfaced as hangs/timeouts instead of clean 5xx responses.This was latent and got exposed when services migrated off the old IdP stack (which dragged spring-tx in transitively) to the new
fireflyframework-security-*modules.Fix
Gate both checks behind a static flag and rely on
&&short-circuit:&&short-circuits, theinstanceof(and its class resolution) is never reached → noNoClassDefFoundError.instanceofruns unchanged, still matching the full subclass hierarchy (e.g.DuplicateKeyException) → existing behavior fully preserved.This aligns the always-on aspect with the converters that already use
@ConditionalOnClassfor the same spring-dao types.Verification
getstatic SPRING_DAO_PRESENTshort-circuits before theinstanceof.NoClassDefFoundError(previously a 20s hang / empty reply).