Rename and nuke a few exceptions

This commit is contained in:
JeremyStar™ 2024-08-31 22:24:22 +02:00
parent cfb52106dc
commit 483afa1e45
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
14 changed files with 127 additions and 218 deletions

View file

@ -27,7 +27,7 @@ import de.staropensource.sosengine.base.utility.information.EngineInformation;
import de.staropensource.sosengine.base.utility.information.JvmInformation;
import de.staropensource.sosengine.base.implementation.versioning.StarOpenSourceVersioningSystem;
import de.staropensource.sosengine.base.event.*;
import de.staropensource.sosengine.base.exception.NoCallAccessException;
import de.staropensource.sosengine.base.exception.IllegalAccessException;
import de.staropensource.sosengine.base.exception.dependency.UnmetDependenciesException;
import de.staropensource.sosengine.base.internal.event.InternalEngineShutdownEvent;
import de.staropensource.sosengine.base.internal.type.DependencySubsystemVector;
@ -523,12 +523,12 @@ public final class Engine extends SubsystemClass {
* Sets the engine state.
*
* @param state new state
* @throws NoCallAccessException if the caller class is unauthorized
* @throws IllegalAccessException if the caller class is unauthorized
* @since v1-alpha2
*/
public void setState(@NotNull EngineState state) throws NoCallAccessException {
public void setState(@NotNull EngineState state) throws IllegalAccessException {
if (!Thread.currentThread().getStackTrace()[2].getClassName().startsWith("de.staropensource.sosengine.base."))
throw new NoCallAccessException("Only classes inside the \"de.staropensource.sosengine.base\" package are allowed to call this method.");
throw new IllegalAccessException("Only classes inside the \"de.staropensource.sosengine.base\" package are allowed to call this method.");
this.state = state;
}

View file

@ -20,7 +20,7 @@
package de.staropensource.sosengine.base;
import de.staropensource.sosengine.base.implementable.ShutdownHandler;
import de.staropensource.sosengine.base.exception.NoCallAccessException;
import de.staropensource.sosengine.base.exception.IllegalAccessException;
import de.staropensource.sosengine.base.logging.LoggerInstance;
import de.staropensource.sosengine.base.type.InternalAccessArea;
import lombok.Getter;
@ -89,12 +89,12 @@ public final class EngineInternals {
* Determines whether access to the specified area is allowed.
*
* @param area internal access area to check
* @throws NoCallAccessException when restricted
* @throws IllegalAccessException when restricted
* @since v1-alpha4
*/
private void isRestricted(@NotNull InternalAccessArea area) throws NoCallAccessException {
private void isRestricted(@NotNull InternalAccessArea area) throws IllegalAccessException {
if (restrictedAreas.contains(area))
throw new NoCallAccessException("The internal access area " + area.name() + " has been restricted");
throw new IllegalAccessException("The internal access area " + area.name() + " has been restricted");
}
/**
@ -125,10 +125,10 @@ public final class EngineInternals {
* Highly recommended to keep enabled.
*
* @param status {@code true} to install, {@code false} otherwise
* @throws NoCallAccessException when restricted
* @throws IllegalAccessException when restricted
* @since v1-alpha4
*/
public void installSafetyShutdownHook(boolean status) throws NoCallAccessException {
public void installSafetyShutdownHook(boolean status) throws IllegalAccessException {
isRestricted(InternalAccessArea.SAFETY_SHUTDOWN_HOOK);
try {
@ -145,10 +145,10 @@ public final class EngineInternals {
* shutting down the JVM safely.
*
* @param shutdownHandler new shutdown handler
* @throws NoCallAccessException when restricted
* @throws IllegalAccessException when restricted
* @since v1-alpha4
*/
public void setShutdownHandler(@NotNull ShutdownHandler shutdownHandler) throws NoCallAccessException {
public void setShutdownHandler(@NotNull ShutdownHandler shutdownHandler) throws IllegalAccessException {
isRestricted(InternalAccessArea.SHUTDOWN_HANDLER_UPDATE);
Engine.getInstance().setShutdownHandler(shutdownHandler);
}
@ -159,10 +159,10 @@ public final class EngineInternals {
* shutting down the JVM safely.
*
* @return shutdown handler
* @throws NoCallAccessException when restricted
* @throws IllegalAccessException when restricted
* @since v1-alpha4
*/
public @NotNull ShutdownHandler getShutdownHandler() throws NoCallAccessException {
public @NotNull ShutdownHandler getShutdownHandler() throws IllegalAccessException {
isRestricted(InternalAccessArea.SHUTDOWN_HANDLER_GET);
return Engine.getInstance().getShutdownHandler();
}

View file

@ -22,17 +22,17 @@ package de.staropensource.sosengine.base.exception;
import org.jetbrains.annotations.NotNull;
/**
* Thrown when the caller class is not allowed to call the throwing method.
* Thrown the throwing method is not allowed to be called.
*
* @since v1-alpha2
* @since v1-alpha4
*/
public class NoCallAccessException extends RuntimeException {
public class IllegalAccessException extends RuntimeException {
/**
* Constructs this exception.
*
* @since v1-alpha2
*/
public NoCallAccessException() {}
public IllegalAccessException() {}
/**
* Constructs this exception.
@ -40,7 +40,7 @@ public class NoCallAccessException extends RuntimeException {
* @param message message
* @since v1-alpha2
*/
public NoCallAccessException(@NotNull String message) {
public IllegalAccessException(@NotNull String message) {
super(message);
}
}

View file

@ -1,64 +0,0 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.sosengine.base.exception;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
/**
* Thrown when a method invokes another method and it throws an unhandled {@link Throwable}.
*
* @since v1-alpha1
*/
@Getter
@SuppressWarnings({ "JavadocDeclaration" })
public class UnexpectedThrowableException extends Exception {
/**
* Contains the throwable supplied to the constructor.
*
* @since v1-alpha1
* -- GETTER --
* Returns the throwable supplied by the constructor.
*
* @return throwable
* @since v1-alpha1
*/
private final @NotNull Throwable throwable;
/**
* Constructs this exception.
*
* @param throwable throwable
* @param message message
*/
public UnexpectedThrowableException(@NotNull Throwable throwable, @NotNull String message) {
super(message);
this.throwable = throwable;
}
/**
* Constructs this exception.
*
* @param throwable throwable
*/
public UnexpectedThrowableException(@NotNull Throwable throwable) {
this.throwable = throwable;
}
}

View file

@ -26,7 +26,7 @@ import org.jetbrains.annotations.NotNull;
*
* @since v1-alpha2
*/
public class NoReflectionAccessException extends Exception {
public class NoAccessException extends Exception {
/**
* Constructs this exception.
*
@ -34,7 +34,7 @@ public class NoReflectionAccessException extends Exception {
* @param name class, method or field name
* @since v1-alpha2
*/
public NoReflectionAccessException(@NotNull String type, @NotNull String name) {
public NoAccessException(@NotNull String type, @NotNull String name) {
super("Access to " + type + " " + name + " has been denied");
}
}

View file

@ -21,13 +21,12 @@ package de.staropensource.sosengine.base.implementable.helper;
import de.staropensource.sosengine.base.EngineConfiguration;
import de.staropensource.sosengine.base.annotation.EventListener;
import de.staropensource.sosengine.base.implementable.Event;
import de.staropensource.sosengine.base.event.LogEvent;
import de.staropensource.sosengine.base.exception.UnexpectedThrowableException;
import de.staropensource.sosengine.base.exception.reflection.InstanceMethodFromStaticContextException;
import de.staropensource.sosengine.base.exception.reflection.InvalidMethodSignature;
import de.staropensource.sosengine.base.exception.reflection.NoReflectionAccessException;
import de.staropensource.sosengine.base.exception.reflection.NoAccessException;
import de.staropensource.sosengine.base.exception.reflection.StaticInitializerException;
import de.staropensource.sosengine.base.implementable.Event;
import de.staropensource.sosengine.base.logging.LoggerInstance;
import de.staropensource.sosengine.base.reflection.Reflect;
import de.staropensource.sosengine.base.reflection.ReflectionMethod;
@ -157,9 +156,7 @@ public final class EventHelper {
for (ReflectionMethod method : getAnnotatedMethods(event)) {
try {
method.invoke(arguments);
} catch (UnexpectedThrowableException exception) {
logger.crash("Event listener method " + method.getName() + " could not be called as an error occurred during reflection", exception, true);
} catch (NoReflectionAccessException exception) {
} catch (NoAccessException exception) {
logger.warn("Event listener method " + method.getName() + " could not be called as the method could not be accessed");
} catch (InvalidMethodSignature exception) {
logger.warn("Event listener method " + method.getName() + " has an invalid method signature");
@ -169,6 +166,8 @@ public final class EventHelper {
logger.warn("Event listener method " + method.getName() + " is not static. Event listener methods must be static for them to be called.");
} catch (StaticInitializerException exception) {
logger.crash("Event listener method " + method.getName() + " could not be called as the static initializer failed", exception.getThrowable(), true);
} catch (Exception exception) {
logger.crash("Event listener method " + method.getName() + " could not be called as an error occurred during reflection", exception, true);
}
}
};

View file

@ -19,7 +19,6 @@
package de.staropensource.sosengine.base.internal.implementation.placeholder.crashhandler;
import de.staropensource.sosengine.base.exception.UnexpectedThrowableException;
import de.staropensource.sosengine.base.implementable.Placeholder;
import de.staropensource.sosengine.base.utility.Miscellaneous;
import org.jetbrains.annotations.NotNull;
@ -91,9 +90,6 @@ public final class Stacktrace implements Placeholder {
.append(Miscellaneous.getStackTraceAsString(throwable, true));
// Handle throwables which contain other throwables
if (throwable instanceof UnexpectedThrowableException unexpectedThrowableException)
getFullStackTrace(unexpectedThrowableException.getThrowable(), stacktrace);
if (throwable instanceof InvocationTargetException invocationTargetException)
getFullStackTrace(invocationTargetException.getTargetException(), stacktrace);

View file

@ -19,8 +19,7 @@
package de.staropensource.sosengine.base.internal.reflection;
import de.staropensource.sosengine.base.exception.UnexpectedThrowableException;
import de.staropensource.sosengine.base.exception.reflection.NoReflectionAccessException;
import de.staropensource.sosengine.base.exception.reflection.NoAccessException;
import de.staropensource.sosengine.base.reflection.ReflectionField;
import de.staropensource.sosengine.base.reflection.ReflectionMethod;
@ -66,12 +65,12 @@ public final class ReflectionAccessWidener {
*
* @param reflectionField {@link ReflectionField} to unlock
* @return updated modifiers. pass those to {@link #lockModifications(ReflectionField, int)} to lock the field again
* @throws UnexpectedThrowableException if the {@code modifiers} field is missing
* @throws NoReflectionAccessException if access to the field has been denied
* @throws NoSuchFieldException if the {@code modifiers} field is missing
* @throws NoAccessException if access to the field has been denied
* @see #lockModifications(ReflectionField, int)
* @since v1-alpha2
*/
public static int unlockModifications(ReflectionField reflectionField) throws UnexpectedThrowableException, NoReflectionAccessException {
public static int unlockModifications(ReflectionField reflectionField) throws NoSuchFieldException, NoAccessException {
int updatedModifiers = 0;
Field field = reflectionField.getField();
@ -79,7 +78,7 @@ public final class ReflectionAccessWidener {
try {
modifiersField = field.getClass().getDeclaredField("modifiers");
} catch (NoSuchFieldException exception) {
throw new UnexpectedThrowableException(exception, "Field \"modifiers\" not present inside field " + field.getName());
throw new NoSuchFieldException("Field \"modifiers\" not present inside field " + field.getName());
}
modifiersField.setAccessible(true);
@ -92,7 +91,7 @@ public final class ReflectionAccessWidener {
try {
modifiersField.setInt(field, field.getModifiers() & ~updatedModifiers);
} catch (IllegalAccessException exception) {
throw new NoReflectionAccessException("field", field.getName());
throw new NoAccessException("field", field.getName());
}
return updatedModifiers;
@ -103,12 +102,12 @@ public final class ReflectionAccessWidener {
*
* @param reflectionMethod {@link ReflectionMethod} to unlock
* @return updated modifiers. pass those to {@link #lockModifications(ReflectionMethod, int)} to lock the method again
* @throws UnexpectedThrowableException if the {@code modifiers} field is missing
* @throws NoReflectionAccessException if access to the method has been denied
* @throws NoSuchFieldException if the {@code modifiers} field is missing
* @throws NoAccessException if access to the method has been denied
* @see #lockModifications(ReflectionMethod, int)
* @since v1-alpha2
*/
public static int unlockModifications(ReflectionMethod reflectionMethod) throws UnexpectedThrowableException, NoReflectionAccessException {
public static int unlockModifications(ReflectionMethod reflectionMethod) throws NoSuchFieldException, NoAccessException {
Method method = reflectionMethod.getMethod();
int updatedModifiers = method.getModifiers();
@ -116,7 +115,7 @@ public final class ReflectionAccessWidener {
try {
modifiersField = method.getClass().getDeclaredField("modifiers");
} catch (NoSuchFieldException exception) {
throw new UnexpectedThrowableException(exception, "Field \"modifiers\" not present inside method " + method.getName());
throw new NoSuchFieldException("Field \"modifiers\" not present inside method " + method.getName());
}
modifiersField.setAccessible(true);
@ -136,7 +135,7 @@ public final class ReflectionAccessWidener {
try {
modifiersField.setInt(method, method.getModifiers() & ~updatedModifiers);
} catch (IllegalAccessException exception) {
throw new NoReflectionAccessException("method", method.getName());
throw new NoAccessException("method", method.getName());
}
return updatedModifiers;
@ -147,19 +146,19 @@ public final class ReflectionAccessWidener {
*
* @param reflectionField {@link ReflectionField} to lock
* @param updatedModifiers original modifiers
* @throws UnexpectedThrowableException if the {@code modifiers} field is missing
* @throws NoReflectionAccessException if access to the field has been denied
* @throws NoSuchFieldException if the {@code modifiers} field is missing
* @throws NoAccessException if access to the field has been denied
* @see #unlockModifications(ReflectionField)
* @since v1-alpha2
*/
public static void lockModifications(ReflectionField reflectionField, int updatedModifiers) throws UnexpectedThrowableException, NoReflectionAccessException {
public static void lockModifications(ReflectionField reflectionField, int updatedModifiers) throws NoSuchFieldException, NoAccessException {
Field field = reflectionField.getField();
Field modifiersField;
try {
modifiersField = field.getClass().getDeclaredField("modifiers");
} catch (NoSuchFieldException exception) {
throw new UnexpectedThrowableException(exception, "Field \"modifiers\" not present inside field " + field.getName());
throw new NoSuchFieldException("Field \"modifiers\" not present inside field " + field.getName());
}
modifiersField.setAccessible(true);
@ -167,7 +166,7 @@ public final class ReflectionAccessWidener {
try {
modifiersField.setInt(field, field.getModifiers() & ~updatedModifiers);
} catch (IllegalAccessException exception) {
throw new NoReflectionAccessException("field", field.getName());
throw new NoAccessException("field", field.getName());
}
modifiersField.setAccessible(false);
@ -178,19 +177,19 @@ public final class ReflectionAccessWidener {
*
* @param reflectionMethod {@link ReflectionMethod} to lock
* @param updatedModifiers original modifiers
* @throws UnexpectedThrowableException if the {@code modifiers} field is missing
* @throws NoReflectionAccessException if access to the method has been denied
* @throws NoSuchFieldException if the {@code modifiers} field is missing
* @throws NoAccessException if access to the method has been denied
* @see #unlockModifications(ReflectionMethod)
* @since v1-alpha2
*/
public static void lockModifications(ReflectionMethod reflectionMethod, int updatedModifiers) throws UnexpectedThrowableException, NoReflectionAccessException {
public static void lockModifications(ReflectionMethod reflectionMethod, int updatedModifiers) throws NoSuchFieldException, NoAccessException {
Method method = reflectionMethod.getMethod();
Field modifiersField;
try {
modifiersField = method.getClass().getDeclaredField("modifiers");
} catch (NoSuchFieldException exception) {
throw new UnexpectedThrowableException(exception, "Field \"modifiers\" not present inside method " + method.getName());
throw new NoSuchFieldException("Field \"modifiers\" not present inside method " + method.getName());
}
modifiersField.setAccessible(true);
@ -198,7 +197,7 @@ public final class ReflectionAccessWidener {
try {
modifiersField.setInt(method, method.getModifiers() & ~updatedModifiers);
} catch (IllegalAccessException exception) {
throw new NoReflectionAccessException("method", method.getName());
throw new NoAccessException("method", method.getName());
}
modifiersField.setAccessible(false);

View file

@ -20,8 +20,7 @@
package de.staropensource.sosengine.base.reflection;
import de.staropensource.sosengine.base.exception.UnexpectedCheckEndException;
import de.staropensource.sosengine.base.exception.UnexpectedThrowableException;
import de.staropensource.sosengine.base.exception.reflection.NoReflectionAccessException;
import de.staropensource.sosengine.base.exception.reflection.NoAccessException;
import de.staropensource.sosengine.base.internal.reflection.ReflectionAccessWidener;
import de.staropensource.sosengine.base.type.reflection.VisibilityModifier;
import lombok.Getter;
@ -158,11 +157,11 @@ public final class ReflectionField {
* Updates the presence of the {@code final} modifier.
*
* @param newValue new presence of the {@code final} modifier
* @throws UnexpectedThrowableException if the {@code modifiers} field is missing
* @throws NoReflectionAccessException if access to the {@code modifiers} field has been denied
* @throws NoSuchFieldException if the {@code modifiers} field is missing
* @throws NoAccessException if access to the {@code modifiers} field has been denied
* @since v1-alpha2
*/
public void setFinal(boolean newValue) throws UnexpectedThrowableException, NoReflectionAccessException {
public void setFinal(boolean newValue) throws NoSuchFieldException, NoAccessException {
// Don't do anything if the new value already matches the current value
if (isFinal() == newValue)
return;
@ -175,14 +174,14 @@ public final class ReflectionField {
try {
modifiersField = field.getClass().getDeclaredField("modifiers");
} catch (NoSuchFieldException exception) {
throw new UnexpectedThrowableException(exception, "Field \"modifiers\" not present inside field " + field.getName());
throw new NoSuchFieldException("Field \"modifiers\" not present inside field " + field.getName());
}
// Update 'modifiers' field
try {
modifiersField.setInt(field, modifiersField.getInt(field) & ~Modifier.FINAL);
} catch (IllegalAccessException e) {
throw new NoReflectionAccessException("field", "modifiers");
throw new NoAccessException("field", "modifiers");
}
// Lock modifications
@ -193,11 +192,11 @@ public final class ReflectionField {
* Updates the presence of the {@code static} modifier.
*
* @param newValue new presence of the {@code static} modifier
* @throws UnexpectedThrowableException if the {@code modifiers} field is missing
* @throws NoReflectionAccessException if access to the {@code modifiers} field has been denied
* @throws NoSuchFieldException if the {@code modifiers} field is missing
* @throws NoAccessException if access to the {@code modifiers} field has been denied
* @since v1-alpha2
*/
public void setStatic(boolean newValue) throws UnexpectedThrowableException, NoReflectionAccessException {
public void setStatic(boolean newValue) throws NoSuchFieldException, NoAccessException {
// Don't do anything if the new value already matches the current value
if (isStatic() == newValue)
return;
@ -210,14 +209,14 @@ public final class ReflectionField {
try {
modifiersField = field.getClass().getDeclaredField("modifiers");
} catch (NoSuchFieldException exception) {
throw new UnexpectedThrowableException(exception, "Field \"modifiers\" not present inside field " + field.getName());
throw new NoSuchFieldException("Field \"modifiers\" not present inside field " + field.getName());
}
// Update 'modifiers' field
try {
modifiersField.setInt(field, modifiersField.getInt(field) & ~Modifier.STATIC);
} catch (IllegalAccessException e) {
throw new NoReflectionAccessException("field", "modifiers");
throw new NoAccessException("field", "modifiers");
}
// Lock modifications
@ -228,11 +227,11 @@ public final class ReflectionField {
* Updates the presence of the {@code transient} modifier.
*
* @param newValue new presence of the {@code transient} modifier
* @throws UnexpectedThrowableException if the {@code modifiers} field is missing
* @throws NoReflectionAccessException if access to the {@code modifiers} field has been denied
* @throws NoSuchFieldException if the {@code modifiers} field is missing
* @throws NoAccessException if access to the {@code modifiers} field has been denied
* @since v1-alpha2
*/
public void setTransient(boolean newValue) throws UnexpectedThrowableException, NoReflectionAccessException {
public void setTransient(boolean newValue) throws NoSuchFieldException, NoAccessException {
// Don't do anything if the new value already matches the current value
if (isTransient() == newValue)
return;
@ -245,14 +244,14 @@ public final class ReflectionField {
try {
modifiersField = field.getClass().getDeclaredField("modifiers");
} catch (NoSuchFieldException exception) {
throw new UnexpectedThrowableException(exception, "Field \"modifiers\" not present inside field " + field.getName());
throw new NoSuchFieldException("Field \"modifiers\" not present inside field " + field.getName());
}
// Update 'modifiers' field
try {
modifiersField.setInt(field, modifiersField.getInt(field) & ~Modifier.TRANSIENT);
} catch (IllegalAccessException e) {
throw new NoReflectionAccessException("field", "modifiers");
throw new NoAccessException("field", "modifiers");
}
// Lock modifications
@ -263,11 +262,11 @@ public final class ReflectionField {
* Updates the presence of the {@code volatile} modifier.
*
* @param newValue new presence of the {@code volatile} modifier
* @throws UnexpectedThrowableException if the {@code modifiers} field is missing
* @throws NoReflectionAccessException if access to the {@code modifiers} field has been denied
* @throws NoSuchFieldException if the {@code modifiers} field is missing
* @throws NoAccessException if access to the {@code modifiers} field has been denied
* @since v1-alpha2
*/
public void setVolatile(boolean newValue) throws UnexpectedThrowableException, NoReflectionAccessException {
public void setVolatile(boolean newValue) throws NoSuchFieldException, NoAccessException {
// Don't do anything if the new value already matches the current value
if (isVolatile() == newValue)
return;
@ -280,14 +279,14 @@ public final class ReflectionField {
try {
modifiersField = field.getClass().getDeclaredField("modifiers");
} catch (NoSuchFieldException exception) {
throw new UnexpectedThrowableException(exception, "Field \"modifiers\" not present inside field " + field.getName());
throw new NoSuchFieldException("Field \"modifiers\" not present inside field " + field.getName());
}
// Update 'modifiers' field
try {
modifiersField.setInt(field, modifiersField.getInt(field) & ~Modifier.VOLATILE);
} catch (IllegalAccessException e) {
throw new NoReflectionAccessException("field", "modifiers");
throw new NoAccessException("field", "modifiers");
}
// Lock modifications
@ -341,14 +340,14 @@ public final class ReflectionField {
* Updates the field with a new value.
*
* @param newValue new value
* @throws NoReflectionAccessException if access to the field has been denied
* @throws NoAccessException if access to the field has been denied
* @since v1-alpha2
*/
public void setValue(Object newValue) throws NoReflectionAccessException {
public void setValue(Object newValue) throws NoAccessException {
try {
field.set(parentClass, newValue);
} catch (IllegalAccessException e) {
throw new NoReflectionAccessException("field", getName());
throw new NoAccessException("field", getName());
}
}
@ -356,14 +355,14 @@ public final class ReflectionField {
* Updates the field with a new value.
*
* @return field's value
* @throws NoReflectionAccessException if access to the field has been denied
* @throws NoAccessException if access to the field has been denied
* @since v1-alpha2
*/
public Object getValue() throws NoReflectionAccessException {
public Object getValue() throws NoAccessException {
try {
return field.get(parentClass);
} catch (IllegalAccessException e) {
throw new NoReflectionAccessException("field", getName());
throw new NoAccessException("field", getName());
}
}
}

View file

@ -20,10 +20,9 @@
package de.staropensource.sosengine.base.reflection;
import de.staropensource.sosengine.base.exception.UnexpectedCheckEndException;
import de.staropensource.sosengine.base.exception.UnexpectedThrowableException;
import de.staropensource.sosengine.base.exception.reflection.InstanceMethodFromStaticContextException;
import de.staropensource.sosengine.base.exception.reflection.InvalidMethodSignature;
import de.staropensource.sosengine.base.exception.reflection.NoReflectionAccessException;
import de.staropensource.sosengine.base.exception.reflection.NoAccessException;
import de.staropensource.sosengine.base.exception.reflection.StaticInitializerException;
import de.staropensource.sosengine.base.internal.reflection.ReflectionAccessWidener;
import de.staropensource.sosengine.base.type.reflection.VisibilityModifier;
@ -162,11 +161,11 @@ public final class ReflectionMethod {
* Updates the presence of the {@code final} modifier.
*
* @param newValue new presence of the {@code final} modifier
* @throws UnexpectedThrowableException if the {@code modifiers} field is missing
* @throws NoReflectionAccessException if access to the {@code modifiers} field has been denied
* @throws NoSuchFieldException if the {@code modifiers} field is missing
* @throws NoAccessException if access to the {@code modifiers} field has been denied
* @since v1-alpha2
*/
public void setFinal(boolean newValue) throws UnexpectedThrowableException, NoReflectionAccessException {
public void setFinal(boolean newValue) throws NoSuchFieldException, NoAccessException {
// Don't do anything if the new value already matches the current value
if (isFinal() == newValue)
return;
@ -179,14 +178,14 @@ public final class ReflectionMethod {
try {
modifiersField = method.getClass().getDeclaredField("modifiers");
} catch (NoSuchFieldException exception) {
throw new UnexpectedThrowableException(exception, "Field \"modifiers\" not present inside method " + method.getName());
throw new NoSuchFieldException("Field \"modifiers\" not present inside method " + method.getName());
}
// Update 'modifiers' field
try {
modifiersField.setInt(method, modifiersField.getInt(method) & ~Modifier.FINAL);
} catch (IllegalAccessException e) {
throw new NoReflectionAccessException("field", "modifiers");
throw new NoAccessException("field", "modifiers");
}
// Lock modifications
@ -197,11 +196,11 @@ public final class ReflectionMethod {
* Updates the presence of the {@code static} modifier.
*
* @param newValue new presence of the {@code static} modifier
* @throws UnexpectedThrowableException if the {@code modifiers} field is missing
* @throws NoReflectionAccessException if access to the {@code modifiers} field has been denied
* @throws NoSuchFieldException if the {@code modifiers} field is missing
* @throws NoAccessException if access to the {@code modifiers} field has been denied
* @since v1-alpha2
*/
public void setStatic(boolean newValue) throws UnexpectedThrowableException, NoReflectionAccessException {
public void setStatic(boolean newValue) throws NoSuchFieldException, NoAccessException {
// Don't do anything if the new value already matches the current value
if (isStatic() == newValue)
return;
@ -214,14 +213,14 @@ public final class ReflectionMethod {
try {
modifiersField = method.getClass().getDeclaredField("modifiers");
} catch (NoSuchFieldException exception) {
throw new UnexpectedThrowableException(exception, "Field \"modifiers\" not present inside method " + method.getName());
throw new NoSuchFieldException("Field \"modifiers\" not present inside method " + method.getName());
}
// Update 'modifiers' field
try {
modifiersField.setInt(method, modifiersField.getInt(method) & ~Modifier.STATIC);
} catch (IllegalAccessException e) {
throw new NoReflectionAccessException("field", "modifiers");
throw new NoAccessException("field", "modifiers");
}
// Lock modifications
@ -232,11 +231,11 @@ public final class ReflectionMethod {
* Updates the presence of the {@code abstract} modifier.
*
* @param newValue new presence of the {@code abstract} modifier
* @throws UnexpectedThrowableException if the {@code modifiers} field is missing
* @throws NoReflectionAccessException if access to the {@code modifiers} field has been denied
* @throws NoSuchFieldException if the {@code modifiers} field is missing
* @throws NoAccessException if access to the {@code modifiers} field has been denied
* @since v1-alpha2
*/
public void setAbstract(boolean newValue) throws UnexpectedThrowableException, NoReflectionAccessException {
public void setAbstract(boolean newValue) throws NoSuchFieldException, NoAccessException {
// Don't do anything if the new value already matches the current value
if (isAbstract() == newValue)
return;
@ -249,14 +248,14 @@ public final class ReflectionMethod {
try {
modifiersField = method.getClass().getDeclaredField("modifiers");
} catch (NoSuchFieldException exception) {
throw new UnexpectedThrowableException(exception, "Field \"modifiers\" not present inside method " + method.getName());
throw new NoSuchFieldException("Field \"modifiers\" not present inside method " + method.getName());
}
// Update 'modifiers' field
try {
modifiersField.setInt(method, modifiersField.getInt(method) & ~Modifier.ABSTRACT);
} catch (IllegalAccessException e) {
throw new NoReflectionAccessException("field", "modifiers");
throw new NoAccessException("field", "modifiers");
}
// Lock modifications
@ -267,11 +266,11 @@ public final class ReflectionMethod {
* Updates the presence of the {@code synchronized} modifier.
*
* @param newValue new presence of the {@code synchronized} modifier
* @throws UnexpectedThrowableException if the {@code modifiers} field is missing
* @throws NoReflectionAccessException if access to the {@code modifiers} field has been denied
* @throws NoSuchFieldException if the {@code modifiers} field is missing
* @throws NoAccessException if access to the {@code modifiers} field has been denied
* @since v1-alpha2
*/
public void setSynchronized(boolean newValue) throws UnexpectedThrowableException, NoReflectionAccessException {
public void setSynchronized(boolean newValue) throws NoSuchFieldException, NoAccessException {
// Don't do anything if the new value already matches the current value
if (isSynchronized() == newValue)
return;
@ -284,14 +283,14 @@ public final class ReflectionMethod {
try {
modifiersField = method.getClass().getDeclaredField("modifiers");
} catch (NoSuchFieldException exception) {
throw new UnexpectedThrowableException(exception, "Field \"modifiers\" not present inside method " + method.getName());
throw new NoSuchFieldException("Field \"modifiers\" not present inside method " + method.getName());
}
// Update 'modifiers' field
try {
modifiersField.setInt(method, modifiersField.getInt(method) & ~Modifier.SYNCHRONIZED);
} catch (IllegalAccessException e) {
throw new NoReflectionAccessException("field", "modifiers");
throw new NoAccessException("field", "modifiers");
}
// Lock modifications
@ -347,15 +346,14 @@ public final class ReflectionMethod {
*
* @param args arguments to pass
* @return method return value
* @throws UnexpectedThrowableException if the {@code modifiers} field could not be found
* @throws NoReflectionAccessException if access to the method has been denied
* @throws NoAccessException if access to the method has been denied
* @throws InvalidMethodSignature if the method signature is incorrect
* @throws InvocationTargetException covers exceptions thrown by the method
* @throws InstanceMethodFromStaticContextException when the target method is non-static and called from a static context
* @throws StaticInitializerException when an the static initializer fails
* @since v1-alpha2
*/
public @Nullable Object invoke(Object... args) throws UnexpectedThrowableException, NoReflectionAccessException, InvalidMethodSignature, InvocationTargetException, InstanceMethodFromStaticContextException, StaticInitializerException {
public @Nullable Object invoke(Object... args) throws NoAccessException, InvalidMethodSignature, InvocationTargetException, InstanceMethodFromStaticContextException, StaticInitializerException {
Object returnValue;
// Allow access to method
@ -365,8 +363,7 @@ public final class ReflectionMethod {
try {
returnValue = method.invoke(parentClass, args);
} catch (IllegalAccessException exception) {
//ReflectionAccessWidener.lockModifications(this, updatedModifiers); // Lock method before throwing exception
throw new NoReflectionAccessException("method", getName());
throw new NoAccessException("method", getName());
} catch (IllegalArgumentException exception) {
throw new InvalidMethodSignature(getName());
} catch (NullPointerException exception) {

View file

@ -19,9 +19,8 @@
package de.staropensource.sosengine.base.utility;
import de.staropensource.sosengine.base.implementable.VersioningSystem;
import de.staropensource.sosengine.base.exception.UnexpectedThrowableException;
import de.staropensource.sosengine.base.exception.dependency.UnmetDependenciesException;
import de.staropensource.sosengine.base.implementable.VersioningSystem;
import de.staropensource.sosengine.base.logging.LoggerInstance;
import de.staropensource.sosengine.base.type.DependencyVector;
import lombok.Getter;
@ -126,11 +125,9 @@ public final class DependencyResolver {
*
* @return itself
* @throws UnmetDependenciesException when dependencies are unmet
* @throws IllegalStateException when encountering an invalid dependency or provider
* @throws UnexpectedThrowableException when some unknown error occurs
* @since v1-alpha1
*/
public synchronized DependencyResolver resolve() throws UnmetDependenciesException, UnexpectedThrowableException {
public synchronized DependencyResolver resolve() throws UnmetDependenciesException {
Map<DependencyVector, String> unmetDependencies = new HashMap<>();
for (DependencyVector vector : vectors) {

View file

@ -19,9 +19,8 @@
package de.staropensource.sosengine.base.srctests.utility;
import de.staropensource.sosengine.base.implementation.versioning.OneNumberVersioningSystem;
import de.staropensource.sosengine.base.exception.UnexpectedThrowableException;
import de.staropensource.sosengine.base.exception.dependency.UnmetDependenciesException;
import de.staropensource.sosengine.base.implementation.versioning.OneNumberVersioningSystem;
import de.staropensource.sosengine.base.srctests.TestBase;
import de.staropensource.sosengine.base.type.DependencyVector;
import de.staropensource.sosengine.base.utility.DependencyResolver;
@ -43,7 +42,7 @@ class DependencyResolverTest extends TestBase {
@ValueSource(ints = {
0, 1, 2, 3, 4, 5
})
void testResolve(int layers) throws UnmetDependenciesException, UnexpectedThrowableException {
void testResolve(int layers) throws UnmetDependenciesException {
if (checkCondition()) return;
getLogger().testCall("testResolve", layers);
@ -269,9 +268,6 @@ class DependencyResolverTest extends TestBase {
getLogger().error("Dependency resolution failed: Unmet dependencies found:");
for (DependencyVector vector : exception.getUnmetDependencies().keySet())
getLogger().error("-> " + vector.getIdentifier() + "=" + vector.getVersion() + ": " + exception.getUnmetDependencies().get(vector));
} else if (throwable instanceof UnexpectedThrowableException exception) {
getLogger().error("Dependency resolution failed: An unexpected throwable was thrown: " + exception.getThrowable().getClass().getName() + ": " + exception.getThrowable().getMessage());
exception.getThrowable().printStackTrace();
} else
getLogger().error("Dependency resolution failed: " + throwable.getMessage());

View file

@ -19,19 +19,18 @@
package de.staropensource.sosengine.windowing.glfw.implementable;
import de.staropensource.sosengine.base.exception.UnexpectedThrowableException;
import de.staropensource.sosengine.base.type.Tristate;
import de.staropensource.sosengine.base.type.vector.Vec2i;
import de.staropensource.sosengine.base.utility.Miscellaneous;
import de.staropensource.sosengine.windowing.WindowingSubsystemConfiguration;
import de.staropensource.sosengine.windowing.implementable.Monitor;
import de.staropensource.sosengine.windowing.implementable.Window;
import de.staropensource.sosengine.windowing.event.RenderingErrorEvent;
import de.staropensource.sosengine.windowing.event.InputEvent;
import de.staropensource.sosengine.windowing.glfw.callback.KeyCallback;
import de.staropensource.sosengine.windowing.glfw.callback.MouseButtonCallback;
import de.staropensource.sosengine.windowing.event.RenderingErrorEvent;
import de.staropensource.sosengine.windowing.exception.NotOnMainThreadException;
import de.staropensource.sosengine.windowing.exception.WindowCreationFailureException;
import de.staropensource.sosengine.windowing.glfw.callback.KeyCallback;
import de.staropensource.sosengine.windowing.glfw.callback.MouseButtonCallback;
import de.staropensource.sosengine.windowing.implementable.Monitor;
import de.staropensource.sosengine.windowing.implementable.Window;
import de.staropensource.sosengine.windowing.type.window.VsyncMode;
import de.staropensource.sosengine.windowing.type.window.WindowMode;
import lombok.Getter;
@ -98,16 +97,16 @@ public class GlfwWindow extends Window {
* @param onTop on top flag
* @param transparent transparency flag
* @param rendering rendering flag
* @throws UnexpectedThrowableException stuff thrown by the {@link #initializeWindow()} and {@link #render()} methods of the implementing windowing API
* @throws Exception stuff thrown by the {@link #initializeWindow()} and {@link #render()} methods of the implementing windowing API
* @since v1-alpha2
*/
public GlfwWindow(@NotNull String name, @NotNull String title, @NotNull Vec2i size, @NotNull Vec2i minimumSize, @NotNull Vec2i maximumSize, @NotNull Vec2i position, @NotNull WindowMode windowMode, @NotNull Monitor monitor, boolean resizable, boolean borderless, boolean focusable, boolean onTop, boolean transparent, boolean rendering) throws UnexpectedThrowableException {
public GlfwWindow(@NotNull String name, @NotNull String title, @NotNull Vec2i size, @NotNull Vec2i minimumSize, @NotNull Vec2i maximumSize, @NotNull Vec2i position, @NotNull WindowMode windowMode, @NotNull Monitor monitor, boolean resizable, boolean borderless, boolean focusable, boolean onTop, boolean transparent, boolean rendering) throws Exception {
super(name, title, size, minimumSize, maximumSize, position, windowMode, monitor, resizable, borderless, focusable, onTop, transparent, rendering);
}
/** {@inheritDoc} */
@Override
protected final void initializeWindow() throws Throwable {
protected final void initializeWindow() throws Exception {
createGlfwWindow(); // Create the GLFW window
initializeGlfwWindow(); // Call GLFW window initialization method
}
@ -119,7 +118,7 @@ public class GlfwWindow extends Window {
* @since v1-alpha2
*/
@SuppressWarnings("RedundantThrows") // done on purpose
protected void initializeGlfwWindow() throws Throwable {}
protected void initializeGlfwWindow() throws Exception {}
/**
* (Re-)Creates the associated GLFW window.

View file

@ -19,7 +19,6 @@
package de.staropensource.sosengine.windowing.implementable;
import de.staropensource.sosengine.base.exception.UnexpectedThrowableException;
import de.staropensource.sosengine.base.logging.LoggerInstance;
import de.staropensource.sosengine.base.type.Tristate;
import de.staropensource.sosengine.base.type.vector.Vec2i;
@ -486,10 +485,10 @@ public abstract class Window implements AutoCloseable {
* @param onTop on top flag
* @param transparent transparency flag
* @param rendering rendering flag
* @throws UnexpectedThrowableException stuff thrown by the {@link #initializeWindow()} and {@link #render()} methods of the implementing windowing API
* @throws Exception stuff thrown by the {@link #initializeWindow()} and {@link #render()} methods of the implementing windowing API
* @since v1-alpha2
*/
protected Window(@NotNull String name, @NotNull String title, @NotNull Vec2i size, @NotNull Vec2i minimumSize, @NotNull Vec2i maximumSize, @NotNull Vec2i position, @NotNull WindowMode windowMode, @NotNull Monitor monitor, boolean resizable, boolean borderless, boolean focusable, boolean onTop, boolean transparent, boolean rendering) throws UnexpectedThrowableException {
protected Window(@NotNull String name, @NotNull String title, @NotNull Vec2i size, @NotNull Vec2i minimumSize, @NotNull Vec2i maximumSize, @NotNull Vec2i position, @NotNull WindowMode windowMode, @NotNull Monitor monitor, boolean resizable, boolean borderless, boolean focusable, boolean onTop, boolean transparent, boolean rendering) throws Exception {
// Initialize variables
this.uniqueIdentifier = UUID.randomUUID();
this.name = name;
@ -510,16 +509,12 @@ public abstract class Window implements AutoCloseable {
// Log about window creation
logger.diag("Creating new window with properties: uniqueIdentifier=" + uniqueIdentifier + " name=\"" + name + "\" title=\"" + title + "\" size=" + size + " minimumSize=" + minimumSize + " maximumSize=" + maximumSize + " position=" + position + " windowMode=" + windowMode + " monitor=" + monitor.getUniqueIdentifier() + " (" + monitor.getName() + ") resizable=" + resizable + " borderless=" + borderless + " focusable=" + focusable + " onTop=" + onTop + " transparent=" + transparent + " rendering=" + rendering);
try {
// Allow windowing API to initialize window
initializeWindow();
// Allow windowing API to initialize window
initializeWindow();
// Update state and render first image
updateState();
render();
} catch (Throwable throwable) {
throw new UnexpectedThrowableException(throwable);
}
// Update state and render first image
updateState();
render();
// Add to window set
windows.add(this);
@ -534,7 +529,7 @@ public abstract class Window implements AutoCloseable {
*
* @since v1-alpha2
*/
protected abstract void initializeWindow() throws Throwable;
protected abstract void initializeWindow() throws Exception;
/**
* Updates the state of this window.
@ -545,7 +540,7 @@ public abstract class Window implements AutoCloseable {
* @throws Throwable thrown by implementing method
* @since v1-alpha2
*/
public abstract void updateState() throws Throwable;
public abstract void updateState() throws Exception;
/**
* Renders this window.
@ -556,7 +551,7 @@ public abstract class Window implements AutoCloseable {
* @throws Throwable thrown by implementing method
* @since v1-alpha2
*/
public abstract void render() throws Throwable;
public abstract void render() throws Exception;
/**
* Alias for {@link #terminate()}.
@ -741,12 +736,12 @@ public abstract class Window implements AutoCloseable {
/**
* Builds a new {@link Window} instance.
*
* @throws IllegalStateException if the window title, size or position is unset
* @throws UnexpectedThrowableException thrown when creating a new {@link Window} instance fails
* @throws IllegalStateException if the window title, size or position is unset
* @throws Exception thrown when creating a new {@link Window} instance fails
* @return {@link Window} instance
* @since v1-alpha2
*/
public @NotNull Window build() throws IllegalStateException, UnexpectedThrowableException {
public @NotNull Window build() throws Exception {
// Booleanized tristates with default values
boolean resizableBoolean = true;
boolean borderlessBoolean = false;
@ -790,13 +785,9 @@ public abstract class Window implements AutoCloseable {
renderingBoolean = false;
// Create new Window instance
try {
return WindowingSubsystem.getInstance().getApi().getInternalApi().getWindowClass()
.getDeclaredConstructor(String.class, String.class, Vec2i.class, Vec2i.class, Vec2i.class, Vec2i.class, WindowMode.class, Monitor.class, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE)
.newInstance(name, title, size, minimumSize, maximumSize, position, windowMode, monitor, resizableBoolean, borderlessBoolean, focusableBoolean, onTopBoolean, transparentBoolean, renderingBoolean);
} catch (Throwable throwable) {
throw new UnexpectedThrowableException(throwable, "Window.Builder was unable to create new Window instance");
}
return WindowingSubsystem.getInstance().getApi().getInternalApi().getWindowClass()
.getDeclaredConstructor(String.class, String.class, Vec2i.class, Vec2i.class, Vec2i.class, Vec2i.class, WindowMode.class, Monitor.class, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE)
.newInstance(name, title, size, minimumSize, maximumSize, position, windowMode, monitor, resizableBoolean, borderlessBoolean, focusableBoolean, onTopBoolean, transparentBoolean, renderingBoolean);
}
/**