Skip to content

1.x: add AnimalSniffer to the build process, fix and suppress violations #4092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
buildscript {
repositories { jcenter() }
dependencies { classpath 'com.netflix.nebula:gradle-rxjava-project-plugin:4.0.0' }
repositories {
jcenter()
}
dependencies {
classpath 'com.netflix.nebula:gradle-rxjava-project-plugin:4.0.0'
classpath 'ru.vyarus:gradle-animalsniffer-plugin:1.1.0'
}
}

description = 'RxJava: Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.'

apply plugin: 'java'
apply plugin: 'pmd'
apply plugin: 'jacoco'
apply plugin: 'ru.vyarus.animalsniffer'
apply plugin: 'nebula.rxjava-project'

repositories {
mavenCentral()
}

dependencies {
signature 'org.codehaus.mojo.signature:java16:1.1@signature'

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'

Expand Down Expand Up @@ -95,4 +107,8 @@ task pmdPrint(dependsOn: 'pmdMain') << {
}
}

build.dependsOn pmdPrint
build.dependsOn pmdPrint

animalsniffer {
annotation = 'rx.internal.util.SuppressAnimalSniffer'
}
1 change: 1 addition & 0 deletions src/main/java/rx/internal/schedulers/NewThreadWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public static void deregisterExecutor(ScheduledExecutorService service) {
}

/** Purges each registered executor and eagerly evicts shutdown executors. */
@SuppressAnimalSniffer // CHM.keySet returns KeySetView in Java 8+; false positive here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible please report an issue back to animalsniffer

static void purgeExecutors() {
try {
Iterator<ScheduledThreadPoolExecutor> it = EXECUTORS.keySet().iterator();
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/rx/internal/util/SuppressAnimalSniffer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright 2016 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package rx.internal.util;

import java.lang.annotation.*;

/**
* Suppress errors by the AnimalSniffer plugin.
*/
@Retention(RetentionPolicy.CLASS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static import makes it more readable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What, you mean RetentionPolicy. Adds more import lines...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's nit of course, totally up to you :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is internal and annotation so I don't expect people looking at its source all the time.

@Documented
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: static imports

public @interface SuppressAnimalSniffer {

}
3 changes: 2 additions & 1 deletion src/main/java/rx/internal/util/UtilityFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package rx.internal.util;

import java.util.Collections;

import rx.functions.Func0;
import rx.functions.Func1;
import rx.functions.Func2;
Expand Down Expand Up @@ -176,5 +178,4 @@ public R call(Object... args) {
return null;
}
}

}
6 changes: 5 additions & 1 deletion src/main/java/rx/internal/util/unsafe/BaseLinkedQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

import java.util.*;

import rx.internal.util.SuppressAnimalSniffer;
import rx.internal.util.atomic.LinkedQueueNode;

abstract class BaseLinkedQueuePad0<E> extends AbstractQueue<E> {
long p00, p01, p02, p03, p04, p05, p06, p07;
long p30, p31, p32, p33, p34, p35, p36, p37;
}

@SuppressAnimalSniffer
abstract class BaseLinkedQueueProducerNodeRef<E> extends BaseLinkedQueuePad0<E> {
protected final static long P_NODE_OFFSET = UnsafeAccess.addressOf(BaseLinkedQueueProducerNodeRef.class, "producerNode");

Expand All @@ -50,6 +52,7 @@ abstract class BaseLinkedQueuePad1<E> extends BaseLinkedQueueProducerNodeRef<E>
long p30, p31, p32, p33, p34, p35, p36, p37;
}

@SuppressAnimalSniffer
abstract class BaseLinkedQueueConsumerNodeRef<E> extends BaseLinkedQueuePad1<E> {
protected final static long C_NODE_OFFSET = UnsafeAccess.addressOf(BaseLinkedQueueConsumerNodeRef.class, "consumerNode");
protected LinkedQueueNode<E> consumerNode;
Expand All @@ -72,8 +75,9 @@ protected final LinkedQueueNode<E> lpConsumerNode() {
*
* @author nitsanw
*
* @param <E>
* @param <E> the element type
*/
@SuppressAnimalSniffer
abstract class BaseLinkedQueue<E> extends BaseLinkedQueueConsumerNodeRef<E> {
long p00, p01, p02, p03, p04, p05, p06, p07;
long p30, p31, p32, p33, p34, p35, p36, p37;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@

import static rx.internal.util.unsafe.UnsafeAccess.UNSAFE;

import java.util.AbstractQueue;
import java.util.Iterator;
import java.util.*;

import rx.internal.util.SuppressAnimalSniffer;

abstract class ConcurrentCircularArrayQueueL0Pad<E> extends AbstractQueue<E> implements MessagePassingQueue<E> {
long p00, p01, p02, p03, p04, p05, p06, p07;
Expand All @@ -40,8 +41,9 @@ abstract class ConcurrentCircularArrayQueueL0Pad<E> extends AbstractQueue<E> imp
*
* @author nitsanw
*
* @param <E>
* @param <E> the element type
*/
@SuppressAnimalSniffer
public abstract class ConcurrentCircularArrayQueue<E> extends ConcurrentCircularArrayQueueL0Pad<E> {
protected static final int SPARSE_SHIFT = Integer.getInteger("sparse.shift", 0);
protected static final int BUFFER_PAD = 32;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

import static rx.internal.util.unsafe.UnsafeAccess.UNSAFE;

import rx.internal.util.SuppressAnimalSniffer;

@SuppressAnimalSniffer
public abstract class ConcurrentSequencedCircularArrayQueue<E> extends ConcurrentCircularArrayQueue<E> {
private static final long ARRAY_BASE;
private static final int ELEMENT_SHIFT;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/rx/internal/util/unsafe/MpmcArrayQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import static rx.internal.util.unsafe.UnsafeAccess.UNSAFE;

import rx.internal.util.SuppressAnimalSniffer;

abstract class MpmcArrayQueueL1Pad<E> extends ConcurrentSequencedCircularArrayQueue<E> {
long p10, p11, p12, p13, p14, p15, p16;
long p30, p31, p32, p33, p34, p35, p36, p37;
Expand All @@ -27,6 +29,7 @@ public MpmcArrayQueueL1Pad(int capacity) {
}
}

@SuppressAnimalSniffer
abstract class MpmcArrayQueueProducerField<E> extends MpmcArrayQueueL1Pad<E> {
private final static long P_INDEX_OFFSET = UnsafeAccess.addressOf(MpmcArrayQueueProducerField.class, "producerIndex");
private volatile long producerIndex;
Expand All @@ -53,6 +56,7 @@ public MpmcArrayQueueL2Pad(int capacity) {
}
}

@SuppressAnimalSniffer
abstract class MpmcArrayQueueConsumerField<E> extends MpmcArrayQueueL2Pad<E> {
private final static long C_INDEX_OFFSET = UnsafeAccess.addressOf(MpmcArrayQueueConsumerField.class, "consumerIndex");
private volatile long consumerIndex;
Expand Down Expand Up @@ -94,6 +98,7 @@ protected final boolean casConsumerIndex(long expect, long newValue) {
* @param <E>
* type of the element stored in the {@link java.util.Queue}
*/
@SuppressAnimalSniffer
public class MpmcArrayQueue<E> extends MpmcArrayQueueConsumerField<E> {
long p40, p41, p42, p43, p44, p45, p46;
long p30, p31, p32, p33, p34, p35, p36, p37;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/rx/internal/util/unsafe/MpscLinkedQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package rx.internal.util.unsafe;

import static rx.internal.util.unsafe.UnsafeAccess.UNSAFE;

import rx.internal.util.SuppressAnimalSniffer;
import rx.internal.util.atomic.LinkedQueueNode;
/**
* This is a direct Java port of the MPSC algorithm as presented <a
Expand All @@ -34,6 +36,7 @@
*
* @param <E>
*/
@SuppressAnimalSniffer
public final class MpscLinkedQueue<E> extends BaseLinkedQueue<E> {

public MpscLinkedQueue() {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/rx/internal/util/unsafe/SpmcArrayQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import static rx.internal.util.unsafe.UnsafeAccess.UNSAFE;

import rx.internal.util.SuppressAnimalSniffer;

abstract class SpmcArrayQueueL1Pad<E> extends ConcurrentCircularArrayQueue<E> {
long p10, p11, p12, p13, p14, p15, p16;
long p30, p31, p32, p33, p34, p35, p36, p37;
Expand All @@ -27,6 +29,7 @@ public SpmcArrayQueueL1Pad(int capacity) {
}
}

@SuppressAnimalSniffer
abstract class SpmcArrayQueueProducerField<E> extends SpmcArrayQueueL1Pad<E> {
protected final static long P_INDEX_OFFSET = UnsafeAccess.addressOf(SpmcArrayQueueProducerField.class, "producerIndex");
private volatile long producerIndex;
Expand All @@ -53,6 +56,7 @@ public SpmcArrayQueueL2Pad(int capacity) {
}
}

@SuppressAnimalSniffer
abstract class SpmcArrayQueueConsumerField<E> extends SpmcArrayQueueL2Pad<E> {
protected final static long C_INDEX_OFFSET = UnsafeAccess.addressOf(SpmcArrayQueueConsumerField.class, "consumerIndex");
private volatile long consumerIndex;
Expand All @@ -79,6 +83,7 @@ public SpmcArrayQueueMidPad(int capacity) {
}
}

@SuppressAnimalSniffer
abstract class SpmcArrayQueueProducerIndexCacheField<E> extends SpmcArrayQueueMidPad<E> {
// This is separated from the consumerIndex which will be highly contended in the hope that this value spends most
// of it's time in a cache line that is Shared(and rarely invalidated)
Expand Down Expand Up @@ -106,6 +111,7 @@ public SpmcArrayQueueL3Pad(int capacity) {
}
}

@SuppressAnimalSniffer
public final class SpmcArrayQueue<E> extends SpmcArrayQueueL3Pad<E> {

public SpmcArrayQueue(final int capacity) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/rx/internal/util/unsafe/SpscArrayQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import static rx.internal.util.unsafe.UnsafeAccess.UNSAFE;

import rx.internal.util.SuppressAnimalSniffer;

abstract class SpscArrayQueueColdField<E> extends ConcurrentCircularArrayQueue<E> {
private static final Integer MAX_LOOK_AHEAD_STEP = Integer.getInteger("jctools.spsc.max.lookahead.step", 4096);
protected final int lookAheadStep;
Expand All @@ -35,6 +37,7 @@ public SpscArrayQueueL1Pad(int capacity) {
}
}

@SuppressAnimalSniffer
abstract class SpscArrayQueueProducerFields<E> extends SpscArrayQueueL1Pad<E> {
protected final static long P_INDEX_OFFSET = UnsafeAccess.addressOf(SpscArrayQueueProducerFields.class, "producerIndex");
protected long producerIndex;
Expand All @@ -54,6 +57,7 @@ public SpscArrayQueueL2Pad(int capacity) {
}
}

@SuppressAnimalSniffer
abstract class SpscArrayQueueConsumerField<E> extends SpscArrayQueueL2Pad<E> {
protected long consumerIndex;
protected final static long C_INDEX_OFFSET = UnsafeAccess.addressOf(SpscArrayQueueConsumerField.class, "consumerIndex");
Expand Down Expand Up @@ -87,6 +91,7 @@ public SpscArrayQueueL3Pad(int capacity) {
*
* @param <E>
*/
@SuppressAnimalSniffer
public final class SpscArrayQueue<E> extends SpscArrayQueueL3Pad<E> {

public SpscArrayQueue(final int capacity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.AbstractQueue;
import java.util.Iterator;

import rx.internal.util.SuppressAnimalSniffer;

abstract class SpscUnboundedArrayQueueProducerFields<E> extends AbstractQueue<E> {
protected long producerIndex;
}
Expand All @@ -46,6 +48,7 @@ abstract class SpscUnboundedArrayQueueConsumerField<E> extends SpscUnboundedArra
protected long consumerIndex;
}

@SuppressAnimalSniffer
public class SpscUnboundedArrayQueue<E> extends SpscUnboundedArrayQueueConsumerField<E>
implements QueueProgressIndicators{
static final int MAX_LOOK_AHEAD_STEP = Integer.getInteger("jctools.spsc.max.lookahead.step", 4096);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/rx/internal/util/unsafe/UnsafeAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.lang.reflect.Field;

import rx.internal.util.SuppressAnimalSniffer;
import sun.misc.Unsafe;

/**
Expand All @@ -26,6 +27,7 @@
* Note that you can force RxJava to not use Unsafe API by setting any value to System Property
* {@code rx.unsafe-disable}.
*/
@SuppressAnimalSniffer
public final class UnsafeAccess {
private UnsafeAccess() {
throw new IllegalStateException("No instances!");
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/rx/internal/operators/OperatorMapPairTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/**
* Copyright 2014 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rx.internal.operators;

import org.junit.*;
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/rx/internal/operators/OperatorSwitchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,9 @@ public void call(Throwable e) {

ts.awaitTerminalEvent(60, TimeUnit.SECONDS);
if (!q.isEmpty()) {
throw new AssertionError("Dropped exceptions", new CompositeException(q));
AssertionError ae = new AssertionError("Dropped exceptions");
ae.initCause(new CompositeException(q));
throw ae;
}
ts.assertNoErrors();
if (ts.getCompletions() == 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/rx/observers/TestSubscriberTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ public void onNext(Integer t) {
ts.awaitTerminalEvent();
}

@Test(timeout = 1000)
@Test(timeout = 5000)
public void testOnErrorCrashCountsDownLatch() {
Observer<Integer> to = new Observer<Integer>() {
@Override
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/rx/plugins/RxJavaPluginsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public Date call(Date date) {
throw new IllegalStateException("Trigger OnNextValue");
}
})
.timeout(500, TimeUnit.MILLISECONDS)
.timeout(5000, TimeUnit.MILLISECONDS)
.toBlocking().first();
fail("Did not expect onNext/onCompleted, got " + notExpected);
} catch (IllegalStateException e) {
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/rx/schedulers/ResetSchedulersTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/**
* Copyright 2016 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rx.schedulers;


Expand Down
2 changes: 1 addition & 1 deletion src/test/java/rx/subjects/BehaviorSubjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public void testCompletedAfterErrorIsNotSent3() {
verify(o2, times(1)).onCompleted();
verifyNoMoreInteractions(o2);
}
@Test(timeout = 1000)
@Test(timeout = 5000)
public void testUnsubscriptionCase() {
BehaviorSubject<String> src = BehaviorSubject.create((String)null);

Expand Down
Loading