ColumnReader NullPointerException when finding a setSomething() method that is not a property mutator#917
Conversation
# Conflicts: # testutil-client/src/main/java/io/spine/testing/client/TestActorRequestFactory.java
|
@dmdashenkov, PTAL. |
Codecov Report
@@ Coverage Diff @@
## master #917 +/- ##
============================================
+ Coverage 93.36% 93.41% +0.05%
- Complexity 3869 3870 +1
============================================
Files 529 529
Lines 12637 12639 +2
Branches 703 701 -2
============================================
+ Hits 11798 11807 +9
+ Misses 609 605 -4
+ Partials 230 227 -3 |
dmdashenkov
left a comment
There was a problem hiding this comment.
@serhii-lekariev, please see my comments.
| .filter(ColumnReader::hasAccessor) | ||
| .filter(ColumnReader::accessorIsAnnotated) | ||
| .map(PropertyDescriptor::getReadMethod) | ||
| .forEach(readMethod -> entityColumns.add(EntityColumn.from(readMethod))); |
There was a problem hiding this comment.
Please use a combination of map and collect instead. forEach must be stateless. In practice, in order to be honest with the functional style coding, forEach is almost never applicable.
There was a problem hiding this comment.
Also, you may extract the method from the descriptor as the first step, filter out nulls and not annotated methods and collect them at once. This is also a performance improvement, since PropertyDescriptor.getReadMethod() looks quite complex and not necessarily fast.
| } | ||
|
|
||
| @Test | ||
| @DisplayName("not confuse a `setSomething()` method with a property mutator") |
There was a problem hiding this comment.
| @DisplayName("not confuse a `setSomething()` method with a property mutator") | |
| @DisplayName("not confuse a setter method with a property mutator") |
| } | ||
|
|
||
| @Column | ||
| public Integer getFortyThree(){ |
There was a problem hiding this comment.
The presence of this @Column makes the test a bit confusing. Can we just drop it and assert that there are no columns?
|
@dmdashenkov, PTAL again. |
dmdashenkov
left a comment
There was a problem hiding this comment.
@serhii-lekariev, please see my new comments.
server/src/main/java/io/spine/server/entity/storage/ColumnReader.java
Outdated
Show resolved
Hide resolved
server/src/main/java/io/spine/server/entity/storage/ColumnReader.java
Outdated
Show resolved
Hide resolved
server/src/main/java/io/spine/server/entity/storage/ColumnReader.java
Outdated
Show resolved
Hide resolved
server/src/main/java/io/spine/server/entity/storage/ColumnReader.java
Outdated
Show resolved
Hide resolved
server/src/main/java/io/spine/server/entity/storage/ColumnReader.java
Outdated
Show resolved
Hide resolved
server/src/test/java/io/spine/server/entity/storage/ColumnReaderTest.java
Outdated
Show resolved
Hide resolved
server/src/test/java/io/spine/server/entity/storage/given/ColumnsTestEnv.java
Outdated
Show resolved
Hide resolved
|
@dmdashenkov, PTAL again. |
dmdashenkov
left a comment
There was a problem hiding this comment.
@serhii-lekariev, please address my final comment. LGTM then.
| checkRepeatedColumnNames(entityColumns); | ||
| return entityColumns; | ||
| PropertyDescriptor[] propertyDescriptors = entityDescriptor.getPropertyDescriptors(); | ||
| ImmutableSet<EntityColumn> annotatedColumns = Arrays |
There was a problem hiding this comment.
| ImmutableSet<EntityColumn> annotatedColumns = Arrays | |
| ImmutableSet<EntityColumn> columns = Arrays |
This PR addresses #912.
Before, when
ColumnReaderwas scanning the class in an attempt to parseColumns, it has tried to get all property descriptors of that class, and once obtained, call agetReadMethod()on every descriptor, to check whether it's annotated with@Column.If a class declares a public
setSomething(Something something)method,somethingbecomes a property, and the declared method becomes a write method for this property.A read method, however, remains undeclared, and
getReadMethod()returns anull, hence the NPE.Now,
ColumnReaderchecks whether a property has an accessor, before attempting to get that accessors annotations and check whether it's actually a@Column.