50
50
import com .sun .tools .attach .AgentInitializationException ;
51
51
import com .sun .tools .attach .AgentLoadException ;
52
52
53
+ import static com .ibm .oti .util .Msg .getString ;
54
+
53
55
/**
54
56
* Handles the initiator end of an attachment to a target VM
55
57
*
@@ -96,7 +98,7 @@ final class OpenJ9VirtualMachine extends VirtualMachine implements Response {
96
98
super (provider , id );
97
99
if ((null == id ) || (null == provider )) {
98
100
/*[MSG "K0554", "Virtual machine ID or display name is null"]*/
99
- throw new NullPointerException (com . ibm . oti . util . Msg . getString ("K0554" )); //$NON-NLS-1$
101
+ throw new NullPointerException (getString ("K0554" )); //$NON-NLS-1$
100
102
}
101
103
new IPC ();
102
104
this .targetId = id ;
@@ -113,7 +115,7 @@ final class OpenJ9VirtualMachine extends VirtualMachine implements Response {
113
115
void attachTarget () throws IOException , AttachNotSupportedException {
114
116
if (null == descriptor ) {
115
117
/*[MSG "K0531", "target not found"]*/
116
- throw new AttachNotSupportedException (com . ibm . oti . util . Msg . getString ("K0531" )); //$NON-NLS-1$
118
+ throw new AttachNotSupportedException (getString ("K0531" )); //$NON-NLS-1$
117
119
}
118
120
AttachNotSupportedException lastException = null ;
119
121
/*[PR CMVC 182802 ]*/
@@ -187,7 +189,7 @@ public synchronized void detach() throws IOException {
187
189
public Properties getAgentProperties () throws IOException {
188
190
if (!targetAttached ) {
189
191
/*[MSG "K0544", "Target not attached"]*/
190
- throw new IOException (com . ibm . oti . util . Msg . getString ("K0544" )); //$NON-NLS-1$
192
+ throw new IOException (getString ("K0544" )); //$NON-NLS-1$
191
193
}
192
194
Properties props = getTargetProperties (false );
193
195
@@ -198,7 +200,7 @@ public Properties getAgentProperties() throws IOException {
198
200
public Properties getSystemProperties () throws IOException {
199
201
if (!targetAttached ) {
200
202
/*[MSG "K0544", "Target not attached"]*/
201
- throw new IOException (com . ibm . oti . util . Msg . getString ("K0544" )); //$NON-NLS-1$
203
+ throw new IOException (getString ("K0544" )); //$NON-NLS-1$
202
204
}
203
205
Properties props = getTargetProperties (true );
204
206
return props ;
@@ -225,7 +227,7 @@ public synchronized void loadAgent(String agent, String options)
225
227
226
228
if (!targetAttached ) {
227
229
/*[MSG "K0544", "Target not attached"]*/
228
- throw new IOException (com . ibm . oti . util . Msg . getString ("K0544" )); //$NON-NLS-1$
230
+ throw new IOException (getString ("K0544" )); //$NON-NLS-1$
229
231
}
230
232
AttachmentConnection .streamSend (commandStream , (createLoadAgent (agent , options )));
231
233
String response = AttachmentConnection .streamReceiveString (responseStream );
@@ -239,7 +241,7 @@ public synchronized void loadAgentLibrary(String agentLibrary,
239
241
240
242
if (!targetAttached ) {
241
243
/*[MSG "K0544", "Target not attached"]*/
242
- throw new IOException (com . ibm . oti . util . Msg . getString ("K0544" )); //$NON-NLS-1$
244
+ throw new IOException (getString ("K0544" )); //$NON-NLS-1$
243
245
}
244
246
AttachmentConnection .streamSend (commandStream , createLoadAgentLibrary (
245
247
agentLibrary , options , false ));
@@ -253,11 +255,11 @@ public synchronized void loadAgentPath(String agentPath, String options)
253
255
IOException {
254
256
if (null == agentPath ) {
255
257
/*[MSG "K0577", "loadAgentPath: null agent path"]*/
256
- throw new AgentLoadException (com . ibm . oti . util . Msg . getString ("K0577" )); //$NON-NLS-1$
258
+ throw new AgentLoadException (getString ("K0577" )); //$NON-NLS-1$
257
259
}
258
260
if (!targetAttached ) {
259
261
/*[MSG "K0544", "Target not attached"]*/
260
- throw new IOException (com . ibm . oti . util . Msg . getString ("K0544" )); //$NON-NLS-1$
262
+ throw new IOException (getString ("K0544" )); //$NON-NLS-1$
261
263
}
262
264
AttachmentConnection .streamSend (commandStream , createLoadAgentLibrary (agentPath ,
263
265
options , true ));
@@ -318,7 +320,7 @@ private static boolean parseResponse(String response) throws IOException,
318
320
}
319
321
if (response .contains (EXCEPTION_IOEXCEPTION )) {
320
322
/*[MSG "K0576","IOException from target: {0}"]*/
321
- throw new IOException (com . ibm . oti . util . Msg . getString ("K0576" , trimmedResponse )); //$NON-NLS-1$
323
+ throw new IOException (getString ("K0576" , trimmedResponse )); //$NON-NLS-1$
322
324
} else if (response .contains (EXCEPTION_AGENT_INITIALIZATION_EXCEPTION )) {
323
325
Integer status = getStatusValue (trimmedResponse );
324
326
if (null == status ) {
@@ -330,13 +332,13 @@ private static boolean parseResponse(String response) throws IOException,
330
332
throw new AgentLoadException (trimmedResponse );
331
333
} else if (response .contains (EXCEPTION_IOEXCEPTION )) {
332
334
/*[MSG "K0576","IOException from target: {0}"]*/
333
- throw new IOException (com . ibm . oti . util . Msg . getString ("K0576" , trimmedResponse )); //$NON-NLS-1$
335
+ throw new IOException (getString ("K0576" , trimmedResponse )); //$NON-NLS-1$
334
336
} else if (response .contains (EXCEPTION_ILLEGAL_ARGUMENT_EXCEPTION )) {
335
337
/*[MSG "K05de","IllegalArgumentException from target: {0}"]*/
336
- throw new IllegalArgumentException (com . ibm . oti . util . Msg . getString ("K05de" , trimmedResponse )); //$NON-NLS-1$
338
+ throw new IllegalArgumentException (getString ("K05de" , trimmedResponse )); //$NON-NLS-1$
337
339
} else if (response .contains (EXCEPTION_ATTACH_OPERATION_FAILED_EXCEPTION )) {
338
340
/*[MSG "k05dc","AttachOperationFailedException from target: {0}"]*/
339
- throw new AttachOperationFailedException (com . ibm . oti . util . Msg . getString ("k05dc" , trimmedResponse )); //$NON-NLS-1$
341
+ throw new AttachOperationFailedException (getString ("k05dc" , trimmedResponse )); //$NON-NLS-1$
340
342
}
341
343
return false ;
342
344
} else if (response .startsWith (ACK ) || response .startsWith (ATTACH_RESULT )) {
@@ -397,18 +399,24 @@ private void tryAttachTarget(int timeout) throws IOException,
397
399
* to attach
398
400
*/
399
401
/*[MSG "K0457", "Target no longer available"]*/
400
- AttachNotSupportedException exc = new AttachNotSupportedException (com . ibm . oti . util . Msg . getString ("K0457" )); //$NON-NLS-1$
402
+ AttachNotSupportedException exc = new AttachNotSupportedException (getString ("K0457" )); //$NON-NLS-1$
401
403
exc .initCause (e );
402
404
throw exc ;
403
405
}
404
406
405
407
if (descriptor .id ().equals (AttachHandler .getVmId ())) {
408
+ String allowAttachSelf_Value = AttachHandler .allowAttachSelf ;
409
+ boolean selfAttachAllowed = "" .equals (allowAttachSelf_Value ) || Boolean .parseBoolean (allowAttachSelf_Value ); //$NON-NLS-1$
410
+ if (!selfAttachAllowed ) {
411
+ /*[MSG "K0646", "Late attach connection to self disabled. Set jdk.attach.allowAttachSelf=true"]*/
412
+ throw new IOException (getString ("K0646" )); //$NON-NLS-1$
413
+ }
406
414
/* I am connecting to myself: bypass the notification and launch the attachment thread directly */
407
415
if (AttachHandler .isAttachApiInitialized ()) {
408
416
AttachHandler .getMainHandler ().connectToAttacher ();
409
417
} else {
410
418
/*[MSG "K0558", "Attach API initialization failed"]*/
411
- throw new AttachNotSupportedException (com . ibm . oti . util . Msg . getString ("K0558" )); //$NON-NLS-1$
419
+ throw new AttachNotSupportedException (getString ("K0558" )); //$NON-NLS-1$
412
420
}
413
421
} else {
414
422
lockAllAttachNotificationSyncFiles (vmds );
@@ -417,7 +425,7 @@ private void tryAttachTarget(int timeout) throws IOException,
417
425
/*[MSG "K0532", "status={0}"]*/
418
426
if ((IPC .JNI_OK != status )
419
427
&& (CommonDirectory .J9PORT_INFO_SHSEM_OPENED_STALE != status )) {
420
- throw new AttachNotSupportedException (com . ibm . oti . util . Msg . getString ("K0532" , status )); //$NON-NLS-1$
428
+ throw new AttachNotSupportedException (getString ("K0532" , status )); //$NON-NLS-1$
421
429
}
422
430
}
423
431
@@ -429,7 +437,7 @@ private void tryAttachTarget(int timeout) throws IOException,
429
437
targetServer .close ();
430
438
IPC .logMessage ("attachTarget SocketTimeoutException on " + portNumber + " to " + targetId ); //$NON-NLS-1$ //$NON-NLS-2$
431
439
/*[MSG "K0539","acknowledgement timeout from {0} on port {1}"]*/
432
- AttachNotSupportedException exc = new AttachNotSupportedException (com . ibm . oti . util . Msg . getString ("K0539" , targetId , portNumber )); //$NON-NLS-1$
440
+ AttachNotSupportedException exc = new AttachNotSupportedException (getString ("K0539" , targetId , portNumber )); //$NON-NLS-1$
433
441
exc .initCause (e );
434
442
throw exc ;
435
443
}
@@ -443,7 +451,7 @@ private void tryAttachTarget(int timeout) throws IOException,
443
451
String response = AttachmentConnection .streamReceiveString (responseStream , ATTACH_CONNECTED_MESSAGE_LENGTH_LIMIT );
444
452
/*[MSG "K0533", "key error: {0}"]*/
445
453
if (!response .contains (' ' + key + ' ' )) {
446
- throw new AttachNotSupportedException (com . ibm . oti . util . Msg . getString ("K0533" , response )); //$NON-NLS-1$
454
+ throw new AttachNotSupportedException (getString ("K0533" , response )); //$NON-NLS-1$
447
455
}
448
456
IPC .logMessage ("attachTarget connected on " , portNumber .toString ()); //$NON-NLS-1$
449
457
targetAttached = true ;
@@ -493,7 +501,7 @@ public void startManagementAgent(Properties agentProperties)
493
501
throws IOException , IllegalArgumentException , AttachOperationFailedException {
494
502
if (!targetAttached ) {
495
503
/*[MSG "K0544", "Target not attached"]*/
496
- throw new IOException (com . ibm . oti . util . Msg . getString ("K0544" )); //$NON-NLS-1$
504
+ throw new IOException (getString ("K0544" )); //$NON-NLS-1$
497
505
} else if (null == agentProperties ) {
498
506
throw new NullPointerException ();
499
507
}
@@ -516,7 +524,7 @@ public void startManagementAgent(Properties agentProperties)
516
524
public String startLocalManagementAgent () throws IOException {
517
525
if (!targetAttached ) {
518
526
/*[MSG "K0544", "Target not attached"]*/
519
- throw new IOException (com . ibm . oti . util . Msg . getString ("K0544" )); //$NON-NLS-1$
527
+ throw new IOException (getString ("K0544" )); //$NON-NLS-1$
520
528
}
521
529
AttachmentConnection .streamSend (commandStream , Command .START_LOCAL_MANAGEMENT_AGENT );
522
530
String response = AttachmentConnection .streamReceiveString (responseStream );
@@ -525,14 +533,14 @@ public String startLocalManagementAgent() throws IOException {
525
533
try {
526
534
if (!parseResponse (response )) {
527
535
/*[MSG "k05dd", "unrecognized response: {0}"]*/
528
- throw new IOException (com . ibm . oti . util . Msg . getString ("k05dd" , response )); //$NON-NLS-1$
536
+ throw new IOException (getString ("k05dd" , response )); //$NON-NLS-1$
529
537
} else if (response .startsWith (ACK )) { /* this came from a legacy VM with dummy start*Agent()s */
530
538
result = response .substring (ACK .length ());
531
539
} else if (response .startsWith (ATTACH_RESULT )) {
532
540
result = response .substring (ATTACH_RESULT .length ());
533
541
} else {
534
542
/*[MSG "k05dd", "unrecognized response: {0}"]*/
535
- throw new IOException (com . ibm . oti . util . Msg . getString ("k05dd" , response )); //$NON-NLS-1$
543
+ throw new IOException (getString ("k05dd" , response )); //$NON-NLS-1$
536
544
}
537
545
} catch (AgentLoadException | IllegalArgumentException | AgentInitializationException e ) {
538
546
IPC .logMessage ("Unexpected exception " + e + " in startLocalManagementAgent" ); //$NON-NLS-1$//$NON-NLS-2$
0 commit comments