Ghidra is a software reverse engineering (SRE) framework
GP-6254 - Fixed NPE in function graph middle-mouse highlighter
dragonmacher0e5095ad9f71
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/ListingMiddleMouseHighlightProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/ListingMiddleMouseHighlightProvider.javaindex 0ce143b404..45e6579691 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/ListingMiddleMouseHighlightProvider.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/ListingMiddleMouseHighlightProvider.java@@ -207,13 +207,17 @@ public class ListingMiddleMouseHighlightProvidercurrentHighlightString = highlightString;+ repaint();+ }++ protected void repaint() {repaintComponent.repaint();}private void clearHighlight() {currentHighlightString = null;currentHighlightPattern = null;- repaintComponent.repaint();+ repaint();}private Pattern createRegisterPattern(Register register, String... highlightStrings) {diff --git a/Ghidra/Features/FunctionGraph/src/main/java/ghidra/app/plugin/core/functiongraph/mvc/FGController.java b/Ghidra/Features/FunctionGraph/src/main/java/ghidra/app/plugin/core/functiongraph/mvc/FGController.javaindex fc45fa4f96..045c1f47e5 100644--- a/Ghidra/Features/FunctionGraph/src/main/java/ghidra/app/plugin/core/functiongraph/mvc/FGController.java+++ b/Ghidra/Features/FunctionGraph/src/main/java/ghidra/app/plugin/core/functiongraph/mvc/FGController.java@@ -21,6 +21,7 @@ import java.awt.geom.Point2D;import java.util.*;import java.util.List;import java.util.function.BiConsumer;+import java.util.function.Supplier;import javax.swing.JComponent;@@ -196,9 +197,10 @@ public class FGController implements ProgramLocationListener, ProgramSelectionLireturn sharedHighlightProvider;}- JComponent centerOverComponent = view.getPrimaryGraphViewer();- sharedHighlightProvider =- new FgHighlightProvider(env.getTool(), centerOverComponent);+ // At the time of construction, the view has not yet built the graph viewer. We will use a+ // supplier to access the viewer on demand. It should be valid at that point.+ Supplier<Component> repaintSupplier = () -> view.getPrimaryGraphViewer();+ sharedHighlightProvider = new FgHighlightProvider(env.getTool(), repaintSupplier);return sharedHighlightProvider;}@@ -1157,10 +1159,10 @@ public class FGController implements ProgramLocationListener, ProgramSelectionLiprivate static class FgHighlightProviderimplements ListingHighlightProvider, ButtonPressedListener {- private ListingMiddleMouseHighlightProvider highlighter;+ private FgMiddleMouseHighlightProvider highlighter;- FgHighlightProvider(PluginTool tool, Component repaintComponent) {- highlighter = new ListingMiddleMouseHighlightProvider(tool, repaintComponent);+ FgHighlightProvider(PluginTool tool, Supplier<Component> repaintSupplier) {+ highlighter = new FgMiddleMouseHighlightProvider(tool, repaintSupplier);}@Override@@ -1173,5 +1175,24 @@ public class FGController implements ProgramLocationListener, ProgramSelectionLiListingField field, MouseEvent event) {highlighter.buttonPressed(location, fieldLocation, field, event);}++ private class FgMiddleMouseHighlightProvider extends ListingMiddleMouseHighlightProvider {++ private Supplier<Component> repaintSupplier;++ public FgMiddleMouseHighlightProvider(PluginTool tool,+ Supplier<Component> repaintSupplier) {+ super(tool, null);+ this.repaintSupplier = repaintSupplier;+ }++ @Override+ protected void repaint() {+ Component c = repaintSupplier.get();+ if (c != null) {+ c.repaint();+ }+ }+ }}}diff --git a/GhidraDocs/GhidraCodingStandards.html b/GhidraDocs/GhidraCodingStandards.htmlindex e0e49fe096..d2dc635bd7 100644--- a/GhidraDocs/GhidraCodingStandards.html+++ b/GhidraDocs/GhidraCodingStandards.html@@ -216,7 +216,7 @@<H2> Formatting </H2><P> Most of these are handled by the Eclipse formatter and are here to document the Ghidraformatting style. The Eclipse formatter can be found in the <I><B>support/eclipse/</B></I>- directory of a Ghidra release, or in the <I><B>eclipse/</B><I> directory of the Ghidra+ directory of a Ghidra release, or in the <I><B>eclipse/</B></I> directory of the Ghidrasource repository.<H3> Line Length </H3><H4> Java code will have a character limit of 100 characters per line. </H4>