52 |
|
} |
53 |
|
|
54 |
|
static class UnrelatedClass { |
55 |
< |
public void checkPrivateAccess() { |
56 |
< |
Exception ex = null; |
55 |
> |
public void checkPackageAccess(AtomicLongFieldUpdaterTest obj) { |
56 |
> |
obj.x = 72L; |
57 |
> |
AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = |
58 |
> |
AtomicLongFieldUpdater.newUpdater |
59 |
> |
(AtomicLongFieldUpdaterTest.class, "x"); |
60 |
> |
assertEquals(72L, a.get(obj)); |
61 |
> |
assertTrue(a.compareAndSet(obj, 72L, 73L)); |
62 |
> |
assertEquals(73L, a.get(obj)); |
63 |
> |
} |
64 |
> |
|
65 |
> |
public void checkPrivateAccess(AtomicLongFieldUpdaterTest obj) { |
66 |
|
try { |
67 |
|
AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = |
68 |
|
AtomicLongFieldUpdater.newUpdater |
69 |
< |
(AtomicLongFieldUpdaterTest.class, "x"); |
70 |
< |
} catch (RuntimeException rex) { |
71 |
< |
ex = rex; |
69 |
> |
(AtomicLongFieldUpdaterTest.class, "privateField"); |
70 |
> |
throw new AssertionError("should throw"); |
71 |
> |
} catch (RuntimeException success) { |
72 |
> |
assertNotNull(success.getCause()); |
73 |
|
} |
64 |
– |
if (ex != null) throw new Error(); |
74 |
|
} |
75 |
|
} |
76 |
|
|
121 |
|
} |
122 |
|
|
123 |
|
/** |
124 |
< |
* construction from unrelated class throws RuntimeException |
124 |
> |
* construction from unrelated class; package access is allowed, |
125 |
> |
* private access is not |
126 |
|
*/ |
127 |
|
public void testUnrelatedClassAccess() { |
128 |
< |
UnrelatedClass s = new UnrelatedClass(); |
129 |
< |
s.checkPrivateAccess(); |
128 |
> |
new UnrelatedClass().checkPackageAccess(this); |
129 |
> |
new UnrelatedClass().checkPrivateAccess(this); |
130 |
|
} |
131 |
|
|
132 |
|
/** |