@@ -1627,13 +1627,6 @@ protected Connection doConnect(File socket) {
16271627 */
16281628 class ForOpenJ9 extends AbstractBase {
16291629
1630- /**
1631- * Property to indicate that the attachment does not validate that the attach file is owned by
1632- * the current user. J9 requires this by its documentation but it does not appear to always be
1633- * implemented.
1634- */
1635- public static final String IGNORE_USER = "net.bytebuddy.attach.j9.ignoreuser" ;
1636-
16371630 /**
16381631 * The temporary folder for attachment files for OpenJ9 VMs.
16391632 */
@@ -1659,20 +1652,34 @@ protected ForOpenJ9(Socket socket) {
16591652 }
16601653
16611654 /**
1662- * Attaches to the supplied process id using the default JNA implementation.
1655+ * Attaches to the supplied process id using the default JNA implementation. This method will not consider
1656+ * attaching to VMs owned by different users than the current user.
16631657 *
16641658 * @param processId The process id.
16651659 * @return A suitable virtual machine implementation.
16661660 * @throws IOException If an IO exception occurs during establishing the connection.
16671661 */
16681662 public static VirtualMachine attach (String processId ) throws IOException {
1663+ return attach (processId , false );
1664+ }
1665+
1666+ /**
1667+ * Attaches to the supplied process id using the default JNA implementation.
1668+ *
1669+ * @param processId The process id.
1670+ * @param ignoreUser {@code true} if VM processes that are owned by different users should be considered.
1671+ * @return A suitable virtual machine implementation.
1672+ * @throws IOException If an IO exception occurs during establishing the connection.
1673+ */
1674+ public static VirtualMachine attach (String processId , boolean ignoreUser ) throws IOException {
16691675 return attach (processId , 5000 , Platform .isWindows ()
16701676 ? new Dispatcher .ForJnaWindowsEnvironment ()
16711677 : new Dispatcher .ForJnaPosixEnvironment (15 , 100 , TimeUnit .MILLISECONDS ));
16721678 }
16731679
16741680 /**
1675- * Attaches to the supplied process id.
1681+ * Attaches to the supplied process id. This method will not consider attaching to VMs owned by
1682+ * different users than the current user.
16761683 *
16771684 * @param processId The process id.
16781685 * @param timeout The timeout for establishing the socket connection.
@@ -1681,6 +1688,20 @@ public static VirtualMachine attach(String processId) throws IOException {
16811688 * @throws IOException If an IO exception occurs during establishing the connection.
16821689 */
16831690 public static VirtualMachine attach (String processId , int timeout , Dispatcher dispatcher ) throws IOException {
1691+ return attach (processId , timeout , dispatcher , false );
1692+ }
1693+
1694+ /**
1695+ * Attaches to the supplied process id.
1696+ *
1697+ * @param processId The process id.
1698+ * @param timeout The timeout for establishing the socket connection.
1699+ * @param dispatcher The connector to use to communicate with the target VM.
1700+ * @param ignoreUser {@code true} if VM processes that are owned by different users should be considered.
1701+ * @return A suitable virtual machine implementation.
1702+ * @throws IOException If an IO exception occurs during establishing the connection.
1703+ */
1704+ public static VirtualMachine attach (String processId , int timeout , Dispatcher dispatcher , boolean ignoreUser ) throws IOException {
16841705 File directory = new File (System .getProperty (IBM_TEMPORARY_FOLDER , dispatcher .getTemporaryFolder (processId )), ".com_ibm_tools_attach" );
16851706 RandomAccessFile attachLock = new RandomAccessFile (new File (directory , "_attachlock" ), "rw" );
16861707 try {
@@ -1695,7 +1716,6 @@ public static VirtualMachine attach(String processId, int timeout, Dispatcher di
16951716 if (vmFolder == null ) {
16961717 throw new IllegalStateException ("No descriptor files found in " + directory );
16971718 }
1698- boolean ignoreUser = Boolean .getBoolean (IGNORE_USER );
16991719 long userId = dispatcher .userId ();
17001720 virtualMachines = new ArrayList <Properties >();
17011721 for (File aVmFolder : vmFolder ) {
0 commit comments