Skip to content
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

min() max() now throw NPE on null values #1692

Merged
merged 2 commits into from
Nov 19, 2016
Merged

min() max() now throw NPE on null values #1692

merged 2 commits into from
Nov 19, 2016

Conversation

danieldietrich
Copy link
Contributor

Fixes #1482

@codecov-io
Copy link

codecov-io commented Nov 19, 2016

Current coverage is 97.06% (diff: 100%)

Merging #1692 into master will not change coverage

@@             master      #1692   diff @@
==========================================
  Files            89         89          
  Lines         11247      11247          
  Methods           0          0          
  Messages          0          0          
  Branches       1888       1888          
==========================================
  Hits          10917      10917          
- Misses          185        187     +2   
+ Partials        145        143     -2   

Powered by Codecov. Last update 7db4c34...7c2c906

} else {
return TreeSet.ofAll(toStringComparator(), Iterator.of(elements));
}
return TreeSet.<T> of(naturalComparator(), elements);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pivovarit do you have a hint how I can tweak Sputnik's default rules to accept this whitespace?

Copy link
Member

Choose a reason for hiding this comment

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

There is a way of overriding the default config by adding some files locally. There it should be possible to tweak it.

@pjagielski can you help?

Choose a reason for hiding this comment

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

Yes, under project' settings, there is a "I have my own config" checkbox which allows you to select a file from repo to use as checkstyle/findbugs/pmd config:

image

image

Copy link
Contributor Author

@danieldietrich danieldietrich Nov 21, 2016

Choose a reason for hiding this comment

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

@pjagielski Thank you, that helps!

@danieldietrich
Copy link
Contributor Author

@pivovarit is there a way to perform the Sputnik checks locally in order to get faster turn-around cycles?


public abstract class AbstractSortedSetTest extends AbstractSetTest {

@Override
abstract protected <T> SortedSet<T> of(T element);

abstract protected <T> SortedSet<T> of(Comparator<? super T> comparator, T element);

Choose a reason for hiding this comment

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

[Checkstyle] ERROR: 'protected' modifier out of order with the JLS suggestions.

@Override
protected <T> BitSet<T> of(Comparator<? super T> comparator, T element) {
// comparator is not used
return this.<T> bsBuilder().of(element);

Choose a reason for hiding this comment

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

[Checkstyle] ERROR: '>' is followed by whitespace.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should be Synchronized with the Idea styles :)


private final java.util.Map<Integer, T> fromIntMap = new java.util.HashMap<>();
private final java.util.Map<T, Integer> toIntMap = new java.util.HashMap<>();
private int nextValue = 0;

Choose a reason for hiding this comment

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

[Checkstyle] ERROR: Variable 'nextValue' explicitly initialized to '0' (default value for its type).

} else {
return TreeSet.ofAll(toStringComparator(), Iterator.of(elements));
}
return TreeSet.<T> of(naturalComparator(), elements);

Choose a reason for hiding this comment

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

[Checkstyle] ERROR: '>' is followed by whitespace.

private Sieve() {
}

private final static List<Function2<Integer, Integer, Option<Integer>>> RULES = List.of(

Choose a reason for hiding this comment

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

[Checkstyle] ERROR: 'static' modifier out of order with the JLS suggestions.

(x, y) -> Option.of((4 * x * x) + (y * y)).filter(n -> n % 12 == 1 || n % 12 == 5),
(x, y) -> Option.of((3 * x * x) + (y * y)).filter(n -> n % 12 == 7),
(x, y) -> Option.of((3 * x * x) - (y * y)).filter(n -> x > y && n % 12 == 11)
);

final static List<Function3<Set<Integer>, Integer, Integer, Set<Integer>>> steps = List.of(
private final static List<Function3<Set<Integer>, Integer, Integer, Set<Integer>>> STEPS = List.of(

Choose a reason for hiding this comment

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

[Checkstyle] ERROR: 'static' modifier out of order with the JLS suggestions.

@danieldietrich
Copy link
Contributor Author

The remaining Sputnik remarks are ok for now - need to tweak the rules a bit.

@danieldietrich danieldietrich merged commit ac9e284 into vavr-io:master Nov 19, 2016
@@ -968,6 +968,16 @@ public void shouldComputeMaxOfBigDecimal() {
assertThat(of(BigDecimal.ZERO, BigDecimal.ONE).max()).isEqualTo(Option.some(BigDecimal.ONE));
}

@Test(expected = NullPointerException.class)
public void shouldThrowNPEWhenMaxOfNullAndInt() {
System.out.println(of(null, 1).max());
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can get rid of the System.out.println


@Test(expected = NullPointerException.class)
public void shouldThrowNPEWhenMaxOfIntAndNull() {
System.out.println(of(1, null).max());
Copy link
Contributor

Choose a reason for hiding this comment

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

same


@Test(expected = NullPointerException.class)
public void shouldThrowNPEWhenMinOfIntAndNull() {
System.out.println(of(1, null).min());
Copy link
Contributor

Choose a reason for hiding this comment

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

same

@Override
protected <T> BitSet<T> of(Comparator<? super T> comparator, T element) {
// comparator is not used
return this.<T> bsBuilder().of(element);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be Synchronized with the Idea styles :)

@Test
public void shouldNarrowQueue() {
final PriorityQueue<Double> doubles = of(1.0d);
public final void shouldNarrowPriorityQueue() {
Copy link
Contributor

Choose a reason for hiding this comment

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

final?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it tests a static method of PriorityQueue. The whole test classes which contains tests for final classes should be also final (HashMapTest, TreeMapTest, ...)

return factors(l)
.filter((d) -> d < l);
static Stream<Long> divisors(long l) {
return factors(l).filter((d) -> d < l);
Copy link
Contributor

Choose a reason for hiding this comment

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

(d) -> can be d ->


Random RND = new Random();
private static final Random RND = new Random();
Copy link
Contributor

Choose a reason for hiding this comment

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

could also be: RND = ThreadLocalRandom.current();

@pivovarit
Copy link
Member

@danieldietrich running Sputnik locally is not possible but you can definitely run those tools that Sputnik uses (those can be included as a part of the build). Before doing this, it's good to create a local config for those tools (which will help with the whitespace problem mentioned earlier)

@danieldietrich danieldietrich deleted the min-max branch November 20, 2016 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants