diff --git a/base/src/main/java/de/staropensource/sosengine/base/Engine.java b/base/src/main/java/de/staropensource/sosengine/base/Engine.java index 7946754..4eb265c 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/Engine.java +++ b/base/src/main/java/de/staropensource/sosengine/base/Engine.java @@ -321,6 +321,8 @@ public final class Engine extends SubsystemClass { //noinspection DataFlowIssue // the crash call will prevent a NullPointerException subsystemsMutable.add(new DependencySubsystemVector(initializedClass.getDependencyVector(), initializedClass)); } catch (Exception exception) { + if (exception.getClass() == IllegalStateException.class && exception.getMessage().startsWith("The version string is invalid: ")) + logger.crash("Failed to initialize subsystem " + clazz.getName() + ": Invalid version string: " + exception.getMessage().replace("The version string is invalid: ", "")); logger.crash("Failed to initialize subsystem " + clazz.getName() + ": Method invocation error", exception); } } diff --git a/base/src/main/java/de/staropensource/sosengine/base/classes/SubsystemClass.java b/base/src/main/java/de/staropensource/sosengine/base/classes/SubsystemClass.java index 9fb18f7..261e50d 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/classes/SubsystemClass.java +++ b/base/src/main/java/de/staropensource/sosengine/base/classes/SubsystemClass.java @@ -22,6 +22,7 @@ package de.staropensource.sosengine.base.classes; import de.staropensource.sosengine.base.Engine; import de.staropensource.sosengine.base.annotations.EngineSubsystem; import de.staropensource.sosengine.base.annotations.EventListener; +import de.staropensource.sosengine.base.exceptions.versioning.InvalidVersionStringException; import de.staropensource.sosengine.base.internal.events.InternalEngineShutdownEvent; import de.staropensource.sosengine.base.logging.LoggerInstance; import de.staropensource.sosengine.base.types.DependencyVector; @@ -73,7 +74,7 @@ public abstract class SubsystemClass { * @see DependencyVector * @since v1-alpha1 */ - public abstract @NotNull DependencyVector getDependencyVector(); + public abstract @NotNull DependencyVector getDependencyVector() throws InvalidVersionStringException; /** * Called on engine shutdown. diff --git a/base/src/main/java/de/staropensource/sosengine/base/types/DependencyVector.java b/base/src/main/java/de/staropensource/sosengine/base/types/DependencyVector.java index 2d7859b..a674e03 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/types/DependencyVector.java +++ b/base/src/main/java/de/staropensource/sosengine/base/types/DependencyVector.java @@ -20,11 +20,13 @@ package de.staropensource.sosengine.base.types; import de.staropensource.sosengine.base.classes.VersioningSystem; +import de.staropensource.sosengine.base.exceptions.versioning.InvalidVersionStringException; import de.staropensource.sosengine.base.utility.DependencyResolver; import lombok.Getter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.lang.reflect.InvocationTargetException; import java.util.HashSet; import java.util.Set; @@ -198,6 +200,18 @@ public class DependencyVector { throw new IllegalStateException("The versioning system is unset"); if (version == null || version.isBlank()) throw new IllegalStateException("The version is unset"); + + // Check if version string is valid + try { + versioningSystem.getDeclaredConstructor(String.class).newInstance(version); + } catch (InvocationTargetException exception) { + if (exception.getTargetException().getClass() == InvalidVersionStringException.class) + throw new IllegalStateException("The version string is invalid: " + exception.getTargetException().getMessage()); + else + throw new IllegalStateException("Version string validation failed: Constructor threw " + exception.getTargetException().getClass().getName() + ": " + exception.getTargetException().getMessage()); + } catch (Exception exception) { + throw new IllegalStateException("Version string validation failed: Threw " + exception.getClass().getName() + ": " + exception.getMessage()); + } } /**