GP-0: Fix NPEs and CMEs from MarkerManager refactor. Fix DiffPlugin.

This commit is contained in:
Dan 2022-02-09 11:22:11 -05:00
parent 7b01170c21
commit a8649865b1
4 changed files with 35 additions and 22 deletions

View file

@ -189,6 +189,9 @@ public class MarkerManager implements MarkerService {
// per-program list // per-program list
MarkerSetCacheEntry entry = markerSetCache.get(program); MarkerSetCacheEntry entry = markerSetCache.get(program);
if (entry == null) {
return;
}
entry.removeSet(markers); entry.removeSet(markers);
// per-group list // per-group list
@ -301,7 +304,8 @@ public class MarkerManager implements MarkerService {
} }
List<MarkerSetImpl> copyMarkerSets(Program program) { List<MarkerSetImpl> copyMarkerSets(Program program) {
return markerSetCache.get(program).copyList(); MarkerSetCacheEntry entry = markerSetCache.get(program);
return entry == null ? List.of() : entry.copyList();
} }
/** /**
@ -311,7 +315,10 @@ public class MarkerManager implements MarkerService {
* @param p the program associated with the markers * @param p the program associated with the markers
*/ */
void markersChanged(Program p) { void markersChanged(Program p) {
markerSetCache.get(p).colorCache.clear(); MarkerSetCacheEntry entry = markerSetCache.get(p);
if (entry != null) {
entry.colorCache.clear();
}
updater.update(); updater.update();
} }

View file

@ -149,15 +149,15 @@ public class MarkerOverviewProvider implements OverviewProvider {
} }
private void doRefresh() { private void doRefresh() {
if (program == null) {
return;
}
for (DockingAction action : actions) { for (DockingAction action : actions) {
tool.removeAction(action); tool.removeAction(action);
} }
actions.clear(); actions.clear();
if (program == null || program.isClosed()) {
return;
}
List<MarkerSetImpl> list = markerManager.copyMarkerSets(program); List<MarkerSetImpl> list = markerManager.copyMarkerSets(program);
// separate the marker sets into grouped and non-grouped // separate the marker sets into grouped and non-grouped

View file

@ -1598,7 +1598,8 @@ public class ProgramDiffPlugin extends ProgramPlugin
showSecondView(); showSecondView();
AddressIndexMap indexMap = diffListingPanel.getAddressIndexMap(); AddressIndexMap indexMap = diffListingPanel.getAddressIndexMap();
fp.setBackgroundColorModel( fp.setBackgroundColorModel(
new MarkerServiceBackgroundColorModel(markerManager, indexMap)); new MarkerServiceBackgroundColorModel(markerManager, secondaryDiffProgram,
indexMap));
} }
finally { finally {
settingLocation = false; settingLocation = false;

View file

@ -18,6 +18,7 @@ package ghidra.framework.data;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
@ -29,10 +30,8 @@ import ghidra.util.Lock;
import ghidra.util.classfinder.ClassSearcher; import ghidra.util.classfinder.ClassSearcher;
/** /**
* An abstract class that provides default behavior for * An abstract class that provides default behavior for DomainObject(s), specifically it handles
* DomainObject(s), specifically it handles listeners and * listeners and change status; the derived class must provide the getDescription() method.
* change status; the derived class must provide the
* getDescription() method.
*/ */
public abstract class DomainObjectAdapter implements DomainObject { public abstract class DomainObjectAdapter implements DomainObject {
@ -56,7 +55,7 @@ public abstract class DomainObjectAdapter implements DomainObject {
new ConcurrentHashMap<EventQueueID, DomainObjectChangeSupport>(); new ConcurrentHashMap<EventQueueID, DomainObjectChangeSupport>();
private volatile boolean eventsEnabled = true; private volatile boolean eventsEnabled = true;
private Set<DomainObjectClosedListener> closeListeners = private Set<DomainObjectClosedListener> closeListeners =
new HashSet<DomainObjectClosedListener>(); new CopyOnWriteArraySet<DomainObjectClosedListener>();
private ArrayList<Object> consumers; private ArrayList<Object> consumers;
protected Map<String, String> metadata = new LinkedHashMap<String, String>(); protected Map<String, String> metadata = new LinkedHashMap<String, String>();
@ -72,12 +71,12 @@ public abstract class DomainObjectAdapter implements DomainObject {
private long modificationNumber = 1; private long modificationNumber = 1;
/** /**
* Construct a new DomainObjectAdapter. * Construct a new DomainObjectAdapter. If construction of this object fails, be sure to release
* If construction of this object fails, be sure to release with consumer. * with consumer.
*
* @param name name of the object * @param name name of the object
* @param timeInterval the time (in milliseconds) to wait before the * @param timeInterval the time (in milliseconds) to wait before the event queue is flushed. If
* event queue is flushed. If a new event comes in before the time expires, * a new event comes in before the time expires, the timer is reset.
* the timer is reset.
* @param bufsize initial size of event buffer * @param bufsize initial size of event buffer
* @param consumer the object that created this domain object * @param consumer the object that created this domain object
*/ */
@ -125,8 +124,9 @@ public abstract class DomainObjectAdapter implements DomainObject {
} }
/** /**
* Returns the hidden user-filesystem associated with * Returns the hidden user-filesystem associated with this objects domain file, or null if
* this objects domain file, or null if unknown. * unknown.
*
* @return user data file system * @return user data file system
*/ */
protected FileSystem getAssociatedUserFilesystem() { protected FileSystem getAssociatedUserFilesystem() {
@ -250,6 +250,7 @@ public abstract class DomainObjectAdapter implements DomainObject {
/** /**
* Return "changed" status * Return "changed" status
*
* @return true if this object has changed * @return true if this object has changed
*/ */
public boolean getChangeStatus() { public boolean getChangeStatus() {
@ -316,9 +317,10 @@ public abstract class DomainObjectAdapter implements DomainObject {
public abstract String getDescription(); public abstract String getDescription();
/** /**
* Fires the specified event. * Fires the specified event.
* @param ev event to fire *
*/ * @param ev event to fire
*/
public void fireEvent(DomainObjectChangeRecord ev) { public void fireEvent(DomainObjectChangeRecord ev) {
modificationNumber++; modificationNumber++;
if (eventsEnabled) { if (eventsEnabled) {
@ -428,6 +430,7 @@ public abstract class DomainObjectAdapter implements DomainObject {
/** /**
* Set default content type * Set default content type
*
* @param doClass default domain object implementation * @param doClass default domain object implementation
*/ */
public static synchronized void setDefaultContentClass(Class<?> doClass) { public static synchronized void setDefaultContentClass(Class<?> doClass) {
@ -447,6 +450,7 @@ public abstract class DomainObjectAdapter implements DomainObject {
/** /**
* Get the ContentHandler associated with the specified content-type. * Get the ContentHandler associated with the specified content-type.
*
* @param contentType domain object content type * @param contentType domain object content type
* @return content handler * @return content handler
*/ */
@ -461,6 +465,7 @@ public abstract class DomainObjectAdapter implements DomainObject {
/** /**
* Get the ContentHandler associated with the specified domain object * Get the ContentHandler associated with the specified domain object
*
* @param dobj domain object * @param dobj domain object
* @return content handler * @return content handler
*/ */