Skip to content

Commit d8f90a1

Browse files
jisedlacthurka
authored andcommitted
Fixed NPE when opening a JDBC .nps snapshot
- added icon for JDBC snapshots
1 parent 01437f1 commit d8f90a1

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

visualvm/profiling/src/com/sun/tools/visualvm/profiling/snapshot/ProfilerSnapshot.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public abstract class ProfilerSnapshot extends Snapshot {
4747

4848
static final Image CPU_ICON = Icons.getImage(ProfilerIcons.CPU);
4949
static final Image MEMORY_ICON = Icons.getImage(ProfilerIcons.MEMORY);
50+
static final Image JDBC_ICON = Icons.getImage(ProfilerIcons.SQL_QUERY);
51+
static final Image SNAPSHOT_ICON = Icons.getImage(ProfilerIcons.SNAPSHOT_DO);
5052
static final Image NODE_BADGE = ImageUtilities.loadImage(
5153
"com/sun/tools/visualvm/core/ui/resources/snapshotBadge.png", true); // NOI18N
5254

visualvm/profiling/src/com/sun/tools/visualvm/profiling/snapshot/ProfilerSnapshotNPS.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,23 @@ protected void remove() {
8383
protected Image resolveIcon() {
8484
try {
8585
int snapshotType = getLoadedSnapshot().getType();
86-
if (snapshotType == LoadedSnapshot.SNAPSHOT_TYPE_CPU) {
87-
return ImageUtilities.mergeImages(CPU_ICON, NODE_BADGE, 0, 0);
88-
} else if (snapshotType == LoadedSnapshot.SNAPSHOT_TYPE_MEMORY_LIVENESS
89-
|| snapshotType == LoadedSnapshot.SNAPSHOT_TYPE_MEMORY_ALLOCATIONS
90-
|| snapshotType == LoadedSnapshot.SNAPSHOT_TYPE_MEMORY_SAMPLED) {
91-
return ImageUtilities.mergeImages(MEMORY_ICON, NODE_BADGE, 0, 0);
92-
} else {
93-
return null;
86+
switch (snapshotType) {
87+
case LoadedSnapshot.SNAPSHOT_TYPE_CPU:
88+
return ImageUtilities.mergeImages(CPU_ICON, NODE_BADGE, 0, 0);
89+
case LoadedSnapshot.SNAPSHOT_TYPE_CPU_JDBC:
90+
return ImageUtilities.mergeImages(JDBC_ICON, NODE_BADGE, 0, 0);
91+
case LoadedSnapshot.SNAPSHOT_TYPE_MEMORY_LIVENESS:
92+
case LoadedSnapshot.SNAPSHOT_TYPE_MEMORY_ALLOCATIONS:
93+
case LoadedSnapshot.SNAPSHOT_TYPE_MEMORY_SAMPLED:
94+
return ImageUtilities.mergeImages(MEMORY_ICON, NODE_BADGE, 0, 0);
95+
default:
96+
// Fallback icon, cannot return null - throws NPE in DataSourceView
97+
return ImageUtilities.mergeImages(SNAPSHOT_ICON, NODE_BADGE, 0, 0);
9498
}
9599
} catch (Exception e) {
96100
LOGGER.log(Level.FINE, "Failed to determine profiler snapshot type", e); // NOI18N
97-
return null;
101+
// Fallback icon, cannot return null - throws NPE in DataSourceView
102+
return ImageUtilities.mergeImages(SNAPSHOT_ICON, NODE_BADGE, 0, 0);
98103
}
99104
}
100105

0 commit comments

Comments
 (0)