Class loading fixes

This commit is contained in:
dragonmacher
2026-05-13 18:15:56 -04:00
parent 56d5167e93
commit 5b0295e0d1
2 changed files with 25 additions and 11 deletions
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,6 +15,9 @@
*/
package ghidra.app.nav;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import ghidra.framework.options.SaveState;
import ghidra.program.model.listing.Program;
import ghidra.program.util.AddressFieldLocation;
@@ -22,9 +25,6 @@ import ghidra.program.util.ProgramLocation;
import ghidra.util.Msg;
import ghidra.util.SystemUtilities;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
public class LocationMemento {
private static final String PROGRAM_PATH = "PROGRAM_PATH_";
private static final String PROGRAM_ID = "PROGRAM_ID";
@@ -86,7 +86,8 @@ public class LocationMemento {
return false;
}
LocationMemento other = (LocationMemento) obj;
return (program == other.program && compareLocations(programLocation, other.programLocation));
return (program == other.program &&
compareLocations(programLocation, other.programLocation));
}
@Override
@@ -142,7 +143,6 @@ public class LocationMemento {
programLocation.saveState(saveState);
}
@SuppressWarnings("unchecked")
// we saved the class, it should be the right type
public static LocationMemento getLocationMemento(SaveState saveState, Program[] programs) {
String className = saveState.getString(MEMENTO_CLASS, null);
@@ -150,10 +150,15 @@ public class LocationMemento {
return null;
}
ClassLoader loader = LocationMemento.class.getClassLoader();
try {
Class<? extends LocationMemento> mementoClass =
(Class<? extends LocationMemento>) Class.forName(className);
Class<?> clazz = Class.forName(className, false, loader);
if (!LocationMemento.class.isAssignableFrom(clazz)) {
Msg.error(LocationMemento.class, "Class is not a LocationMemento: " + clazz);
return null;
}
Class<? extends LocationMemento> mementoClass = clazz.asSubclass(LocationMemento.class);
Constructor<? extends LocationMemento> constructor =
mementoClass.getConstructor(SaveState.class, Program[].class);
return constructor.newInstance(saveState, programs);
@@ -182,7 +187,8 @@ public class LocationMemento {
// Cause could be null here, so protect.
String message = cause == null ? "" : cause.getMessage();
throw new IllegalArgumentException("Unexpected exception restoring memento: " + message);
throw new IllegalArgumentException(
"Unexpected exception restoring memento: " + message);
}
return null;