-
Notifications
You must be signed in to change notification settings - Fork 12
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
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -114,6 +115,14 @@ void fromImplementedInterface() { | |||
} | |||
} | |||
|
|||
@Test | |||
@DisplayName("not confuse a `setSomething()` method with a property mutator") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ImmutableSet<EntityColumn> annotatedColumns = Arrays | |
ImmutableSet<EntityColumn> columns = Arrays |
This PR addresses #912.
Before, when
ColumnReader
was 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,something
becomes 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,
ColumnReader
checks whether a property has an accessor, before attempting to get that accessors annotations and check whether it's actually a@Column
.