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

Introduce Error Prone #712

Merged
merged 56 commits into from
May 31, 2018
Merged

Introduce Error Prone #712

merged 56 commits into from
May 31, 2018

Conversation

alexander-yevsyukov
Copy link
Contributor

@alexander-yevsyukov alexander-yevsyukov commented May 28, 2018

This PR adds Error Prone to the project and replaces @Nullable from javax.annotations with the one from the Checker Framework.

It also starts eliminating the final qualifier for the local variables, since under Java 8 they are effectively final. We also want to improve the readability in the light of introduction of the var declaration in Java 10. So, this request also introduced an improved layout for calling builder methods.
For information about the var and final matters, please see this page.

Spine version advances to 0.10.41-SNAPSHOT.

@alexander-yevsyukov alexander-yevsyukov self-assigned this May 28, 2018
Conflicts:
	client/src/test/java/io/spine/client/ColumnFiltersShould.java
	ext.gradle
	server/src/main/java/io/spine/server/entity/storage/EntityColumn.java
	server/src/test/java/io/spine/server/entity/storage/ColumnTypeRegistryShould.java
	server/src/test/java/io/spine/server/storage/RecordStorageShould.java
Conflicts:
	client/src/test/java/io/spine/client/ColumnFiltersShould.java
	ext.gradle
	server/src/main/java/io/spine/server/entity/storage/EntityColumn.java
	server/src/test/java/io/spine/server/entity/storage/ColumnTypeRegistryShould.java
	server/src/test/java/io/spine/server/storage/RecordStorageShould.java
@codecov
Copy link

codecov bot commented May 28, 2018

Codecov Report

Merging #712 into master will increase coverage by 0.07%.
The diff coverage is 95.16%.

@@             Coverage Diff              @@
##             master     #712      +/-   ##
============================================
+ Coverage     93.24%   93.32%   +0.07%     
- Complexity     3014     3033      +19     
============================================
  Files           369      371       +2     
  Lines         10349    10390      +41     
  Branches        676      678       +2     
============================================
+ Hits           9650     9696      +46     
+ Misses          504      500       -4     
+ Partials        195      194       -1

@alexander-yevsyukov alexander-yevsyukov requested review from armiol and dmdashenkov and removed request for armiol May 28, 2018 01:42
@SpineEventEngine SpineEventEngine deleted a comment May 28, 2018
@SpineEventEngine SpineEventEngine deleted a comment May 30, 2018
@SpineEventEngine SpineEventEngine deleted a comment May 30, 2018
@SpineEventEngine SpineEventEngine deleted a comment May 30, 2018
Conflicts:
	client/src/test/java/io/spine/client/ColumnFiltersShould.java
	client/src/test/java/io/spine/client/CommandFactoryShould.java
	client/src/test/java/io/spine/client/QueriesTest.java
	client/src/test/java/io/spine/client/QueryBuilderShould.java
	client/src/test/java/io/spine/client/QueryFactoryShould.java
	client/src/test/java/io/spine/core/CommandsTest.java
	ext.gradle
	server/src/main/java/io/spine/server/aggregate/Aggregate.java
	server/src/main/java/io/spine/server/entity/TransactionalEntity.java
	server/src/test/java/io/spine/server/bc/BoundedContextShould.java
	server/src/test/java/io/spine/server/entity/RecordBasedRepositoryShould.java
	server/src/test/java/io/spine/server/storage/RecordStorageShould.java
@SpineEventEngine SpineEventEngine deleted a comment May 31, 2018
@alexander-yevsyukov
Copy link
Contributor Author

@dmdashenkov, PTAL.

Copy link
Contributor

@dmdashenkov dmdashenkov left a comment

Choose a reason for hiding this comment

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

@alexander-yevsyukov, please see my new comments.


assertEquals(3, FluentIterable.from(filter)
.size());
assertEquals(3, StreamSupport.stream(filter.spliterator(), false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we join the stream of commands (see above) and this one?

Also, please use Stream.of(...) instead of ImmutableList.of(...).stream().

boolean noEvents = record.getEventList()
.isEmpty();
if (noEvents && snapshotIsNotSet) {
throw new IllegalStateException("AggregateStateRecord instance should have either "
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use Exceptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need here as we're not passing arguments to a formatted string.

return Optional.absent();
}

while (historyBackward.hasNext()
Copy link
Contributor

Choose a reason for hiding this comment

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

Please extract the loop into a separate method.

@@ -353,8 +353,8 @@ protected CommandDispatcherRegistry registry() {
* the current runtime environment.
*/
private static boolean detectThreadsAllowed() {
final boolean appEngine = ServerEnvironment.getInstance()
.isAppEngine();
boolean appEngine = ServerEnvironment.getInstance()
Copy link
Contributor

Choose a reason for hiding this comment

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

We're now allowed to spawn threads on AppEngine. I believe this is irrelevant now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This matter needs more attention across the whole codebase. Please file an issue for this and link it into this PR.

return result;
}

static boolean hasNullableReturn(Method getter) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe, mayReturnNull(Method)?

&& getter.getParameterTypes().length == 0,
"Method `%s` is not a getter.", getter);
checkArgument(getAnnotatedVersion(getter).isPresent(),
format("Entity column getter should be annotated with `%s`.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove redundant format, as checkArgument is capable of string formatting on its own.

Class<?> returnType = getter.getReturnType();
Class<?> wrapped = wrap(returnType);
checkArgument(Serializable.class.isAssignableFrom(wrapped),
format("Cannot create column of non-serializable type %s by method %s.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

.collect(Collectors.toSet());
Set<TenantId> tenants = Streams.stream(events)
.map(Events::getTenantId)
.collect(Collectors.toSet());
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a static import for toSet().

return aggregateStateRecord;
List<Event> expectedEvents = records.stream()
.map(TO_EVENT)
.collect(Collectors.toList());
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a static import for toList().

return eventMessage.equals(phase.getEventMessage())
&& event.getContext()
.equals(phase.getContext())
&& phase.isSuccessful() == successful;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please split the expression into 3 with 3 local variables to make it more debuggable.

@SpineEventEngine SpineEventEngine deleted a comment May 31, 2018
@SpineEventEngine SpineEventEngine deleted a comment May 31, 2018
Also improved a method name.
Conflicts:
	client/src/test/java/io/spine/core/CommandsTest.java
	client/src/test/java/io/spine/grpc/StreamObserversTest.java
	core/src/test/java/io/spine/change/BooleanMismatchShould.java
	core/src/test/java/io/spine/change/DoubleMismatchShould.java
	core/src/test/java/io/spine/change/FloatMismatchShould.java
	core/src/test/java/io/spine/change/IntMismatchShould.java
	core/src/test/java/io/spine/change/LongMismatchShould.java
	core/src/test/java/io/spine/change/StringMismatchShould.java
@alexander-yevsyukov
Copy link
Contributor Author

@dmdashenkov, PTAL.

@SpineEventEngine SpineEventEngine deleted a comment May 31, 2018
Copy link
Contributor

@dmdashenkov dmdashenkov left a comment

Choose a reason for hiding this comment

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

@alexander-yevsyukov, LGTM in general.
Let's discuss the remaining comments vocally if needed.

fiveSecondsAgo)
.filter(wereWithinPeriod(minutesAgo(3), secondsAgo(10))
::apply)
.collect(toList());

assertEquals(3, StreamSupport.stream(filter.spliterator(), false)
.count());
Copy link
Contributor

Choose a reason for hiding this comment

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

This is still strange.

First, we generate a stream, then convert it to list and then back to stream, and, at last, obtain count().

@Test
@DisplayName("consider command not scheduled when no scheduling options are present")
void recognizeNotScheduled() {
final Command cmd = requestFactory.createCommand(StringValue.getDefaultInstance());
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we use final here again?

@SpineEventEngine SpineEventEngine deleted a comment May 31, 2018
@SpineEventEngine SpineEventEngine deleted a comment May 31, 2018
@alexander-yevsyukov alexander-yevsyukov merged commit f47da52 into master May 31, 2018
@alexander-yevsyukov alexander-yevsyukov deleted the error-prone branch June 1, 2018 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants