@@ -36,15 +36,7 @@ public SpscArrayQueueL1Pad(int capacity) {
3636}
3737
3838abstract class SpscArrayQueueProducerFields <E > extends SpscArrayQueueL1Pad <E > {
39- protected final static long P_INDEX_OFFSET ;
40- static {
41- try {
42- P_INDEX_OFFSET =
43- UNSAFE .objectFieldOffset (SpscArrayQueueProducerFields .class .getDeclaredField ("producerIndex" ));
44- } catch (NoSuchFieldException e ) {
45- throw new RuntimeException (e );
46- }
47- }
39+ protected final static long P_INDEX_OFFSET = UnsafeAccess .addressOf (SpscArrayQueueProducerFields .class , "producerIndex" );
4840 protected long producerIndex ;
4941 protected long producerLookAhead ;
5042
@@ -64,15 +56,7 @@ public SpscArrayQueueL2Pad(int capacity) {
6456
6557abstract class SpscArrayQueueConsumerField <E > extends SpscArrayQueueL2Pad <E > {
6658 protected long consumerIndex ;
67- protected final static long C_INDEX_OFFSET ;
68- static {
69- try {
70- C_INDEX_OFFSET =
71- UNSAFE .objectFieldOffset (SpscArrayQueueConsumerField .class .getDeclaredField ("consumerIndex" ));
72- } catch (NoSuchFieldException e ) {
73- throw new RuntimeException (e );
74- }
75- }
59+ protected final static long C_INDEX_OFFSET = UnsafeAccess .addressOf (SpscArrayQueueConsumerField .class , "consumerIndex" );
7660 public SpscArrayQueueConsumerField (int capacity ) {
7761 super (capacity );
7862 }
@@ -116,6 +100,9 @@ public SpscArrayQueue(final int capacity) {
116100 */
117101 @ Override
118102 public boolean offer (final E e ) {
103+ if (e == null ) {
104+ throw new NullPointerException ("null elements not allowed" );
105+ }
119106 // local load of field to avoid repeated loads after volatile reads
120107 final E [] lElementBuffer = buffer ;
121108 final long index = producerIndex ;
0 commit comments