This repository was archived by the owner on Feb 20, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +13
-10
lines changed
src/main/java/de/interguess/javamoduleloader/module Expand file tree Collapse file tree 3 files changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ plugins {
44}
55
66group ' de.interguess'
7- version ' 1.0-beta'
7+ version ' 1.0.1 -beta'
88
99repositories {
1010 mavenCentral()
Original file line number Diff line number Diff line change 11package de .interguess .javamoduleloader .module ;
22
3+ import de .interguess .javamoduleloader .exception .ModuleLoadException ;
34import org .jetbrains .annotations .NotNull ;
45import org .jetbrains .annotations .Nullable ;
56
@@ -44,7 +45,7 @@ public interface Module<T> {
4445 * @param requiredSuperClass the required superclass of the main class
4546 * @param mainClass the name of the main class
4647 * @return the main class of the module
47- * @throws ClassNotFoundException if the main class could not be found
48+ * @throws ModuleLoadException if there was an error loading or verifying the main class
4849 */
49- @ NotNull Class <T > getMainClassByName (@ NotNull Class <T > requiredSuperClass , @ NotNull String mainClass ) throws ClassNotFoundException ;
50+ @ NotNull Class <T > getMainClassByName (@ NotNull Class <T > requiredSuperClass , @ NotNull String mainClass ) throws ModuleLoadException ;
5051}
Original file line number Diff line number Diff line change @@ -50,15 +50,17 @@ public SimpleModule(File file) throws ModuleLoadException {
5050 }
5151
5252 @ Override
53- public @ NotNull Class <T > getMainClassByName (@ NotNull Class <T > requiredSuperClass , @ NotNull String mainClass ) throws ClassNotFoundException {
54- Class <?> clazz = classLoader .loadClass (mainClass );
53+ public @ NotNull Class <T > getMainClassByName (@ NotNull Class <T > requiredSuperClass , @ NotNull String mainClass ) throws ModuleLoadException {
54+ try {
55+ Class <?> clazz = classLoader .loadClass (mainClass );
56+
57+ if (!requiredSuperClass .isAssignableFrom (clazz )) {
58+ throw new ModuleLoadException ("Class " + mainClass + " does not extend or implement " + requiredSuperClass .getName ());
59+ }
5560
56- if (clazz == null ) {
57- throw new ClassNotFoundException ("Class not found: " + mainClass );
58- } else if (!clazz .getSuperclass ().equals (requiredSuperClass )) {
59- throw new ClassNotFoundException ("Class " + mainClass + " does not implement " + requiredSuperClass .getName ());
60- } else {
6161 return (Class <T >) clazz ;
62+ } catch (ClassNotFoundException e ) {
63+ throw new ModuleLoadException ("Class not found: " + mainClass , e );
6264 }
6365 }
6466}
You can’t perform that action at this time.
0 commit comments