Skip to content

Commit 3b24a0f

Browse files
authored
Merge pull request #1964 from SAP/pr-jdk-17.0.16+2
Merge to tag jdk-17.0.16+2
2 parents d86f230 + 23901f3 commit 3b24a0f

File tree

4 files changed

+66
-35
lines changed

4 files changed

+66
-35
lines changed

test/jdk/com/sun/tools/attach/Agent.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,6 +28,7 @@
2828
* the given port.
2929
*/
3030
import java.net.Socket;
31+
import java.net.InetAddress;
3132
import java.net.InetSocketAddress;
3233
import java.io.IOException;
3334

@@ -38,7 +39,7 @@ public static void agentmain(String args) throws IOException {
3839
int port = Integer.parseInt(args);
3940
System.out.println("Agent connecting back to Tool....");
4041
Socket s = new Socket();
41-
s.connect( new InetSocketAddress(port) );
42+
s.connect(new InetSocketAddress(InetAddress.getLoopbackAddress(), port));
4243
System.out.println("Agent connected to Tool.");
4344
s.close();
4445
}

test/jdk/com/sun/tools/attach/BasicTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
import java.io.File;
2525
import java.io.IOException;
26+
import java.net.InetAddress;
27+
import java.net.InetSocketAddress;
2628
import java.net.ServerSocket;
2729
import java.net.Socket;
2830
import java.util.List;
@@ -213,7 +215,8 @@ public static void main(String args[]) throws Exception {
213215

214216
System.out.println(" - Test: End-to-end connection with agent");
215217

216-
ServerSocket ss = new ServerSocket(0);
218+
ServerSocket ss = new ServerSocket();
219+
ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
217220
int port = ss.getLocalPort();
218221

219222
System.out.println(" - Loading Agent.jar into target VM ...");
@@ -231,7 +234,8 @@ public static void main(String args[]) throws Exception {
231234

232235
System.out.println(" - Test: End-to-end connection with RedefineAgent");
233236

234-
ServerSocket ss2 = new ServerSocket(0);
237+
ServerSocket ss2 = new ServerSocket();
238+
ss2.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
235239
int port2 = ss2.getLocalPort();
236240

237241
System.out.println(" - Loading RedefineAgent.jar into target VM ...");

test/jdk/com/sun/tools/attach/RedefineAgent.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2006, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -32,6 +32,7 @@
3232
* 6446941 java.lang.instrument: multiple agent attach fails (first agent chooses capabilities)
3333
*/
3434
import java.net.Socket;
35+
import java.net.InetAddress;
3536
import java.net.InetSocketAddress;
3637
import java.io.IOException;
3738
import java.util.Arrays;
@@ -104,7 +105,7 @@ public static void agentmain(String args, Instrumentation inst) throws Exception
104105
int port = Integer.parseInt(args);
105106
System.out.println("RedefineAgent connecting back to Tool....");
106107
Socket s = new Socket();
107-
s.connect( new InetSocketAddress(port) );
108+
s.connect(new InetSocketAddress(InetAddress.getLoopbackAddress(), port));
108109
System.out.println("RedefineAgent connected to Tool.");
109110

110111
testRedefine(inst);
Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,27 +28,34 @@
2828
* @key headful
2929
* @bug 4529206
3030
* @summary JToolBar - setFloating does not work correctly
31-
* @author Konstantin Eremin
3231
* @run main bug4529206
3332
*/
3433

35-
import javax.swing.*;
36-
import java.awt.*;
34+
import java.awt.BorderLayout;
35+
import java.awt.Dimension;
36+
import java.awt.Robot;
3737
import java.awt.event.ActionEvent;
3838
import java.awt.event.ActionListener;
39+
import javax.swing.JButton;
40+
import javax.swing.JFrame;
41+
import javax.swing.JPanel;
42+
import javax.swing.JTextField;
43+
import javax.swing.JToolBar;
44+
import javax.swing.SwingUtilities;
3945

40-
public class bug4529206 extends JFrame {
46+
public class bug4529206 {
4147
static JFrame frame;
4248
static JToolBar jToolBar1;
43-
public bug4529206() {
44-
setDefaultCloseOperation(EXIT_ON_CLOSE);
45-
JPanel jPanFrame = (JPanel) this.getContentPane();
49+
static JButton jButton1;
50+
51+
private static void test() {
52+
frame = new JFrame();
53+
JPanel jPanFrame = (JPanel) frame.getContentPane();
4654
jPanFrame.setLayout(new BorderLayout());
47-
this.setSize(new Dimension(200, 100));
48-
this.setLocation(125, 75);
49-
this.setTitle("Test Floating Toolbar");
55+
frame.setSize(new Dimension(200, 100));
56+
frame.setTitle("Test Floating Toolbar");
5057
jToolBar1 = new JToolBar();
51-
JButton jButton1 = new JButton("Float");
58+
jButton1 = new JButton("Float");
5259
jPanFrame.add(jToolBar1, BorderLayout.NORTH);
5360
JTextField tf = new JTextField("click here");
5461
jPanFrame.add(tf);
@@ -58,36 +65,54 @@ public void actionPerformed(ActionEvent e) {
5865
buttonPressed(e);
5966
}
6067
});
61-
makeToolbarFloat();
62-
setVisible(true);
68+
69+
frame.setUndecorated(true);
70+
frame.setLocationRelativeTo(null);
71+
frame.setVisible(true);
6372
}
6473

65-
private void makeToolbarFloat() {
74+
private static void makeToolbarFloat() {
6675
javax.swing.plaf.basic.BasicToolBarUI ui = (javax.swing.plaf.basic.BasicToolBarUI) jToolBar1.getUI();
6776
if (!ui.isFloating()) {
6877
ui.setFloatingLocation(100, 100);
6978
ui.setFloating(true, jToolBar1.getLocation());
7079
}
7180
}
7281

73-
private void buttonPressed(ActionEvent e) {
82+
private static void buttonPressed(ActionEvent e) {
7483
makeToolbarFloat();
7584
}
7685

7786
public static void main(String[] args) throws Exception {
78-
SwingUtilities.invokeAndWait(new Runnable() {
79-
public void run() {
80-
frame = new bug4529206();
81-
}
82-
});
83-
Robot robot = new Robot();
84-
robot.waitForIdle();
85-
SwingUtilities.invokeAndWait(new Runnable() {
86-
public void run() {
87-
if (frame.isFocused()) {
88-
throw (new RuntimeException("setFloating does not work correctly"));
87+
try {
88+
SwingUtilities.invokeAndWait(new Runnable() {
89+
public void run() {
90+
test();
8991
}
90-
}
91-
});
92+
});
93+
Robot robot = new Robot();
94+
robot.waitForIdle();
95+
robot.delay(1000);
96+
97+
SwingUtilities.invokeAndWait(() -> {
98+
makeToolbarFloat();
99+
});
100+
101+
robot.waitForIdle();
102+
SwingUtilities.invokeAndWait(new Runnable() {
103+
public void run() {
104+
if (frame.isFocused()) {
105+
throw
106+
new RuntimeException("setFloating does not work correctly");
107+
}
108+
}
109+
});
110+
} finally {
111+
SwingUtilities.invokeAndWait(() -> {
112+
if (frame != null) {
113+
frame.dispose();
114+
}
115+
});
116+
}
92117
}
93118
}

0 commit comments

Comments
 (0)