ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/AtomicIntegerFieldUpdaterTest.java
(Generate patch)

Comparing jsr166/src/test/tck/AtomicIntegerFieldUpdaterTest.java (file contents):
Revision 1.30 by dl, Sun Nov 8 15:34:00 2015 UTC vs.
Revision 1.31 by jsr166, Mon Nov 9 18:42:41 2015 UTC

# Line 38 | Line 38 | public class AtomicIntegerFieldUpdaterTe
38          }
39  
40          public void checkCompareAndSetProtectedSub() {
41 <            AtomicIntegerFieldUpdater<AtomicIntegerFieldUpdaterTest> a;
42 <            a = updaterFor("protectedField");
43 <            protectedField = 1;
41 >            AtomicIntegerFieldUpdater<AtomicIntegerFieldUpdaterTest> a =
42 >                AtomicIntegerFieldUpdater.newUpdater
43 >                (AtomicIntegerFieldUpdaterTest.class, "protectedField");
44 >            this.protectedField = 1;
45              assertTrue(a.compareAndSet(this, 1, 2));
46              assertTrue(a.compareAndSet(this, 2, -4));
47              assertEquals(-4, a.get(this));
# Line 52 | Line 53 | public class AtomicIntegerFieldUpdaterTe
53      }
54  
55      static class UnrelatedClass {
56 <        public void checkPrivateAccess() {
57 <            Exception ex = null;
56 >        public void checkPackageAccess(AtomicIntegerFieldUpdaterTest obj) {
57 >            obj.x = 72;
58 >            AtomicIntegerFieldUpdater<AtomicIntegerFieldUpdaterTest> a =
59 >                AtomicIntegerFieldUpdater.newUpdater
60 >                (AtomicIntegerFieldUpdaterTest.class, "x");
61 >            assertEquals(72, a.get(obj));
62 >            assertTrue(a.compareAndSet(obj, 72, 73));
63 >            assertEquals(73, a.get(obj));
64 >        }
65 >
66 >        public void checkPrivateAccess(AtomicIntegerFieldUpdaterTest obj) {
67              try {
68                  AtomicIntegerFieldUpdater<AtomicIntegerFieldUpdaterTest> a =
69                      AtomicIntegerFieldUpdater.newUpdater
70 <                    (AtomicIntegerFieldUpdaterTest.class, "x");
71 <            } catch (RuntimeException rex) {
72 <                ex = rex;
70 >                    (AtomicIntegerFieldUpdaterTest.class, "privateField");
71 >                throw new AssertionError("should throw");
72 >            } catch (RuntimeException success) {
73 >                assertNotNull(success.getCause());
74              }
64            if (ex != null) throw new Error();
75          }
76      }
77  
# Line 112 | Line 122 | public class AtomicIntegerFieldUpdaterTe
122      }
123  
124      /**
125 <     * construction from unrelated class throws RuntimeException
125 >     * construction from unrelated class; package access is allowed,
126 >     * private access is not
127       */
128      public void testUnrelatedClassAccess() {
129 <        UnrelatedClass s = new UnrelatedClass();
130 <        s.checkPrivateAccess();
129 >        new UnrelatedClass().checkPackageAccess(this);
130 >        new UnrelatedClass().checkPrivateAccess(this);
131      }
132  
133      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines