blob: 35753b82d599566e78b3bbd763184a3332cc797c [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * @test
3 * @bug 4278121
4 * @summary Ensure that calling unbind() on an unbound name returns
5 * successfully.
6 */
7
8import javax.naming.*;
9
10public class UnbindIdempotent {
11
12 public static void main(String[] args) throws Exception {
13
14 // Create registry on port 1099 if one is not already running.
15 try {
16 java.rmi.registry.LocateRegistry.createRegistry(1099);
17 } catch (java.rmi.RemoteException e) {
18 }
19
20 Context ictx = new InitialContext();
21 Context rctx;
22 try {
23 rctx = (Context)ictx.lookup("rmi://localhost:1099");
24 } catch (NamingException e) {
25 // Unable to set up for test.
26 return;
27 }
28
29 // Attempt to unbind a name that is not already bound.
30 try {
31 rctx.unbind("_bogus_4278121_");
32 } catch (NameNotFoundException e) {
33 throw new Exception("Test failed: unbind() call not idempotent");
34 }
35 }
36}