From 3778faa4104888b56a80722647cd4ae07283f853 Mon Sep 17 00:00:00 2001 From: Yeser Amer Date: Mon, 15 Jul 2024 15:19:08 +0200 Subject: [PATCH] Fix DMN Validation when build fails --- .../validation/DMNDomainValidatorImpl.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/kie-wb-common-dmn/kie-wb-common-dmn-backend/src/main/java/org/kie/workbench/common/dmn/backend/validation/DMNDomainValidatorImpl.java b/kie-wb-common-dmn/kie-wb-common-dmn-backend/src/main/java/org/kie/workbench/common/dmn/backend/validation/DMNDomainValidatorImpl.java index 4cabebd9a2b..085c0f7fbaf 100644 --- a/kie-wb-common-dmn/kie-wb-common-dmn-backend/src/main/java/org/kie/workbench/common/dmn/backend/validation/DMNDomainValidatorImpl.java +++ b/kie-wb-common-dmn/kie-wb-common-dmn-backend/src/main/java/org/kie/workbench/common/dmn/backend/validation/DMNDomainValidatorImpl.java @@ -125,9 +125,7 @@ public Collection validate(final Diagram diagram, final Reader[] aDMNXMLReaders = new Reader[]{}; - final ClassLoader classLoader = getClassLoader(diagram); - - final DMNValidator dmnValidator = getDmnValidator(classLoader); + final DMNValidator dmnValidator = getDmnValidator(diagram); final List messages = dmnValidator .validateUsing(DMNValidator.Validation.VALIDATE_MODEL, @@ -148,8 +146,12 @@ public Collection validate(final Diagram diagram, } } - DMNValidator getDmnValidator(final ClassLoader classLoader) { - return DMNValidatorFactory.newValidator(classLoader, Collections.emptyList()); + DMNValidator getDmnValidator(Diagram diagram) { + final ClassLoader classLoader = getClassLoader(diagram); + + return classLoader != null ? + DMNValidatorFactory.newValidator(classLoader, Collections.emptyList()) : + DMNValidatorFactory.newValidator(); } ClassLoader getClassLoader(final Diagram diagram) { @@ -157,8 +159,10 @@ ClassLoader getClassLoader(final Diagram diagram) { final WorkspaceProject project = workspaceProjectService.resolveProject(path); final Module module = project.getMainModule(); final BuildHelper.BuildResult result = buildHelper.build(module); - final ClassLoader classLoader = ((InternalKieModule) result.getBuilder().getKieModuleIgnoringErrors()).getModuleClassLoader(); - return classLoader; + if (result.getBuilder() != null) { + return ((InternalKieModule) result.getBuilder().getKieModuleIgnoringErrors()).getModuleClassLoader(); + } + return null; } DMNValidator.ValidatorBuilder.ValidatorImportReaderResolver getValidatorImportReaderResolver(final Metadata metadata) {