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

Comparing jsr166/src/test/tck/Atomic8Test.java (file contents):
Revision 1.7 by jsr166, Sat Sep 24 12:54:31 2016 UTC vs.
Revision 1.8 by jsr166, Sat Sep 24 18:38:13 2016 UTC

# Line 43 | Line 43 | public class Atomic8Test extends JSR166T
43      volatile int anIntField;
44      volatile Integer anIntegerField;
45  
46 <    AtomicLongFieldUpdater aLongFieldUpdater() {
46 >    AtomicLongFieldUpdater<Atomic8Test> aLongFieldUpdater() {
47          return AtomicLongFieldUpdater.newUpdater
48              (Atomic8Test.class, "aLongField");
49      }
50  
51 <    AtomicIntegerFieldUpdater anIntFieldUpdater() {
51 >    AtomicIntegerFieldUpdater<Atomic8Test> anIntFieldUpdater() {
52          return AtomicIntegerFieldUpdater.newUpdater
53              (Atomic8Test.class, "anIntField");
54      }
# Line 501 | Line 501 | public class Atomic8Test extends JSR166T
501              () -> aLongFieldUpdater().getAndUpdate(this, null),
502              () -> anIntFieldUpdater().getAndUpdate(this, null),
503              () -> anIntegerFieldUpdater().getAndUpdate(this, null),
504            ////() -> aLongFieldUpdater().getAndUpdate(null, Atomic8Test::addLong17),
505            ////() -> anIntFieldUpdater().getAndUpdate(null, Atomic8Test::addInt17),
506            ////() -> anIntegerFieldUpdater().getAndUpdate(null, Atomic8Test::addInteger17),
504          };
505          assertThrows(NullPointerException.class, throwingActions);
506      }
# Line 564 | Line 561 | public class Atomic8Test extends JSR166T
561          assertThrows(NullPointerException.class, throwingActions);
562      }
563  
564 +    /**
565 +     * Object arguments for parameters of type T that are not
566 +     * instances of the class passed to the newUpdater call will
567 +     * result in a ClassCastException being thrown.
568 +     */
569 +    public void testFieldUpdaters_ClassCastException() {
570 +        // Use raw types to allow passing wrong object type, provoking CCE
571 +        final AtomicLongFieldUpdater longUpdater = aLongFieldUpdater();
572 +        final AtomicIntegerFieldUpdater intUpdater = anIntFieldUpdater();
573 +        final AtomicReferenceFieldUpdater refUpdater = anIntegerFieldUpdater();
574 +        final Object obj = new Object();
575 +        for (Object x : new Object[]{ new Object(), null }) {
576 +            Runnable[] throwingActions = {
577 +                () -> longUpdater.get(x),
578 +                () -> intUpdater.get(x),
579 +                () -> refUpdater.get(x),
580 +
581 +                () -> longUpdater.set(x, 17L),
582 +                () -> intUpdater.set(x, 17),
583 +                () -> refUpdater.set(x, (Integer) 17),
584 +
585 +                () -> longUpdater.addAndGet(x, 17L),
586 +                () -> intUpdater.addAndGet(x, 17),
587 +
588 +                () -> longUpdater.getAndUpdate(x, y -> y),
589 +                () -> intUpdater.getAndUpdate(x, y -> y),
590 +                () -> refUpdater.getAndUpdate(x, y -> y),
591 +
592 +                () -> longUpdater.compareAndSet(x, 17L, 42L),
593 +                () -> intUpdater.compareAndSet(x, 17, 42),
594 +                () -> refUpdater.compareAndSet(x, (Integer) 17, (Integer) 42),
595 +            };
596 +            assertThrows(ClassCastException.class, throwingActions);
597 +        }
598 +    }
599 +
600   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines