Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions hdfview/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@
<arguments combine.children="append">
<argument>--icon</argument>
<argument>${project.basedir}/../package_files/macosx/HDFView.icns</argument>
<argument>--resource-dir</argument>
<argument>${project.basedir}/../package_files/macosx</argument>
<argument>--mac-entitlements</argument>
<argument>${project.basedir}/../lib/macosx/distribution.entitlements</argument>
<argument>--java-options</argument>
Expand Down
19 changes: 15 additions & 4 deletions hdfview/src/main/java/hdf/view/Chart.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@

private Color barColor;

/**
* Tracks whether barColor was allocated by us and needs disposal.
* System colors should not be disposed.
*/
private boolean isBarColorOwned = false;

/** histogram style chart. */
public static final int HISTOGRAM = 0;

Expand Down Expand Up @@ -152,7 +158,8 @@

if (style == HISTOGRAM) {
isInteger = true;
barColor = new Color(Display.getDefault(), new RGB(0, 0, 255));
// Use system color directly - no need to create a duplicate
barColor = Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION);
}
else {
isInteger = false;
Expand Down Expand Up @@ -218,7 +225,8 @@
{
if (curFont != null)
curFont.dispose();
if (barColor != null)
// Only dispose barColor if we created it (not a system color)
if (isBarColorOwned && barColor != null)
barColor.dispose();
}
});
Expand Down Expand Up @@ -277,8 +285,11 @@
RGB newColor = dialog.open();

if (newColor != null) {
barColor.dispose();
barColor = new Color(Display.getDefault(), newColor);
// Dispose old color only if we created it
if (isBarColorOwned && barColor != null)
barColor.dispose();
barColor = new Color(Display.getDefault(), newColor);
isBarColorOwned = true; // We now own this color and must dispose it
chartP.redraw();
}
}
Expand Down Expand Up @@ -315,7 +326,7 @@
/** Find and set the minimum and maximum values of the data. */
private void findDataRange()
{
if (data == null)

Check warning

Code scanning / CodeQL

Dereferenced variable may be null Warning

Variable
barColor
may be null at this access as suggested by
this
null guard.
return;

ymin = data[0][0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ public void widgetDisposed(DisposeEvent e)

cellValueField = new Text(cellValueFieldScroller, SWT.MULTI | SWT.BORDER | SWT.WRAP);
cellValueField.setEditable(false);
cellValueField.setBackground(new Color(display, 255, 255, 240));
cellValueField.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
cellValueField.setEnabled(false);
cellValueField.setFont(curFont);

Expand Down
Loading