Skip to content

Commit 076d261

Browse files
committed
GH-442 handle null returned from getCommandLine() and getJvmArgs()
1 parent 1cdb5db commit 076d261

File tree

6 files changed

+15
-10
lines changed

6 files changed

+15
-10
lines changed

visualvm/application/src/org/graalvm/visualvm/application/ApplicationDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ protected static String resolveCustomName(Application application) {
167167
Jvm jvm = JvmFactory.getJVMFor(application);
168168
if (jvm.isBasicInfoSupported()) {
169169
String args = jvm.getJvmArgs();
170-
int propIndex = args.indexOf(DISPLAY_NAME_PROPERTY);
170+
int propIndex = args != null ? args.indexOf(DISPLAY_NAME_PROPERTY) : -1;
171171

172172
if (propIndex != -1) { // display name propery detected on commandline
173173
propIndex += DISPLAY_NAME_PROPERTY.length();

visualvm/application/src/org/graalvm/visualvm/application/type/JavaPluginApplicationTypeFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public ApplicationType createModelFor(Application application) {
5151
Jvm jvm = JvmFactory.getJVMFor(application);
5252
if (jvm.isBasicInfoSupported()) {
5353
String args = jvm.getJvmArgs();
54-
int plugin_index = args.indexOf(JAVA_PLUGIN);
54+
int plugin_index = args != null ? args.indexOf(JAVA_PLUGIN) : -1;
5555
if (plugin_index != -1) {
5656
String version;
5757
int version_index = plugin_index + JAVA_PLUGIN.length();

visualvm/application/src/org/graalvm/visualvm/application/type/JavaWebStartApplicationTypeFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ public ApplicationType createModelFor(Application application) {
5050
Jvm jvm = JvmFactory.getJVMFor(application);
5151
if (jvm.isBasicInfoSupported()) {
5252
String args = jvm.getJvmArgs();
53-
int jws_index = args.indexOf(JWS);
54-
if (jws_index != -1) {
53+
if (args != null && args.contains(JWS)) {
5554
return new JavaWebStartApplicationType("");
5655
}
5756
}

visualvm/application/src/org/graalvm/visualvm/application/type/NetBeansApplicationTypeFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private boolean isNetBeans(Jvm jvm, String mainClass) {
6666

6767
protected Set<String> computeClusters(Jvm jvm) {
6868
String args = jvm.getJvmArgs();
69-
int clusterIndex = args.indexOf(NETBEANS_DIRS);
69+
int clusterIndex = args != null ? args.indexOf(NETBEANS_DIRS) : -1;
7070
String pathSeparator = jvm.getJavaHome().contains("\\")?";":":"; // NOI18N
7171
String separator = pathSeparator.equals(":")?"/":"\\"; // NOI18N
7272
Set<String> clusters = new HashSet<>();

visualvm/jvm/src/org/graalvm/visualvm/jvm/JVMImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ protected void initStaticData() {
595595

596596
private String getJvmArgsJvmstat() {
597597
String args = jvmstatModel.getJvmArgs();
598-
if (args.length() == 1024) {
598+
if (args != null && args.length() == 1024) {
599599
String longArgs = null;
600600
AttachModel attach = getAttach();
601601
if (attach != null) {

visualvm/tools/src/org/graalvm/visualvm/tools/jvmstat/JvmJvmstatModel.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,14 @@ public boolean isAttachable() {
228228

229229
public String getMainArgs() {
230230
String commandLine = getCommandLine();
231-
String arg0 = getFirstArgument();
232231

233-
int firstSpace = arg0.length();
234-
if (firstSpace < commandLine.length()) {
235-
return commandLine.substring(firstSpace);
232+
if (commandLine != null) {
233+
String arg0 = getFirstArgument();
234+
235+
int firstSpace = arg0.length();
236+
if (firstSpace < commandLine.length()) {
237+
return commandLine.substring(firstSpace);
238+
}
236239
}
237240
return null;
238241
}
@@ -248,6 +251,8 @@ public String getMainArgs() {
248251
*/
249252
public String getMainClass() {
250253
String mainClassName = getFirstArgument();
254+
255+
if (mainClassName == null) return null;
251256
// if we are on localhost try read main class from jar file
252257
if (application.isLocalApplication()) {
253258
File jarFile = new File(mainClassName);
@@ -278,6 +283,7 @@ private String getFirstArgument() {
278283
String commandLine = getCommandLine();
279284
String mainClassName = null;
280285

286+
if (commandLine == null) return mainClassName;
281287
// search for jar file
282288
int jarIndex = commandLine.indexOf(JAR_SUFFIX);
283289
if (jarIndex != -1) {

0 commit comments

Comments
 (0)