You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "orionlibs (via GitHub)" <gi...@apache.org> on 2023/06/26 17:49:44 UTC
[GitHub] [commons-text] orionlibs opened a new pull request, #434: added null-check to avoid NullPointerException
orionlibs opened a new pull request, #434:
URL: https://github.com/apache/commons-text/pull/434
(no comment)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-text] kinow commented on a diff in pull request #434: added null-check to avoid NullPointerException
Posted by "kinow (via GitHub)" <gi...@apache.org>.
kinow commented on code in PR #434:
URL: https://github.com/apache/commons-text/pull/434#discussion_r1242635013
##########
src/main/java/org/apache/commons/text/RandomStringGenerator.java:
##########
@@ -183,9 +183,11 @@ public Builder filteredBy(final CharacterPredicate... predicates) {
* @since 1.2
*/
public Builder selectFrom(final char... chars) {
- characterList = new ArrayList<>();
- for (final char c : chars) {
- characterList.add(c);
+ if(chars != null) {
Review Comment:
Checkstyle issues in the PR (you can run `mvn` locally and that should do the same as GH Actions).
```bash
Error: src/main/java/org/apache/commons/text/RandomStringGenerator.java:[244,13] (whitespace) WhitespaceAfter: 'if' is not followed by whitespace.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-text] garydgregory merged pull request #434: Add null-check in RandomStringGenerator#selectFrom() to avoid NullPointerException
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory merged PR #434:
URL: https://github.com/apache/commons-text/pull/434
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-text] codecov-commenter commented on pull request #434: added null-check to avoid NullPointerException
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #434:
URL: https://github.com/apache/commons-text/pull/434#issuecomment-1608065154
## [Codecov](https://app.codecov.io/gh/apache/commons-text/pull/434?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
> Merging [#434](https://app.codecov.io/gh/apache/commons-text/pull/434?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (1f1a312) into [master](https://app.codecov.io/gh/apache/commons-text/commit/7f3f9f5c7d0cd693e201a8e9f265b380694806e9?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (7f3f9f5) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.
```diff
@@ Coverage Diff @@
## master #434 +/- ##
=========================================
Coverage 97.12% 97.12%
Complexity 2332 2332
=========================================
Files 84 84
Lines 5780 5781 +1
Branches 936 937 +1
=========================================
+ Hits 5614 5615 +1
Misses 87 87
Partials 79 79
```
| [Impacted Files](https://app.codecov.io/gh/apache/commons-text/pull/434?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [...org/apache/commons/text/RandomStringGenerator.java](https://app.codecov.io/gh/apache/commons-text/pull/434?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2NvbW1vbnMvdGV4dC9SYW5kb21TdHJpbmdHZW5lcmF0b3IuamF2YQ==) | `93.50% <100.00%> (+0.08%)` | :arrow_up: |
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-text] garydgregory commented on a diff in pull request #434: added null-check to avoid NullPointerException
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #434:
URL: https://github.com/apache/commons-text/pull/434#discussion_r1242733312
##########
src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java:
##########
@@ -212,6 +212,14 @@ public void testSelectFromCharVarargs() {
}
}
+ @Test
+ public void testSelectFromNullCharVarargs() {
+ final String str = "abc";
+ final RandomStringGenerator generator = new RandomStringGenerator.Builder().selectFrom(null).build();
+ final String randomText = generator.generate(5);
+ assertThat(randomText.isEmpty()).isFalse();
Review Comment:
You need to assert the results are correct, not that any old output was generated.
##########
src/main/java/org/apache/commons/text/RandomStringGenerator.java:
##########
@@ -183,9 +183,11 @@ public Builder filteredBy(final CharacterPredicate... predicates) {
* @since 1.2
*/
public Builder selectFrom(final char... chars) {
- characterList = new ArrayList<>();
- for (final char c : chars) {
- characterList.add(c);
+ if (chars != null) {
+ characterList = new ArrayList<>();
Review Comment:
-1: This PR breaks the documented contract in the Javadoc (the contract is still broken for null). This is unexpected because the consequence of null input should be the same as empty (size 0) input but in fact, is not.
For example:
```
builder.
selectFrom('a')
selectFrom();
```
gives us a `characterList` of `[]` but:
```
builder.
selectFrom('a')
selectFrom(null);
```
gives us a `characterList` of `['a']` instead of `[]`.
IOW, null input and empty should be the same. If not, why not? Or am I missing something? Why doesn't `selectFrom()` always reset `characterList`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-text] orionlibs commented on a diff in pull request #434: added null-check to avoid NullPointerException
Posted by "orionlibs (via GitHub)" <gi...@apache.org>.
orionlibs commented on code in PR #434:
URL: https://github.com/apache/commons-text/pull/434#discussion_r1242655479
##########
src/main/java/org/apache/commons/text/RandomStringGenerator.java:
##########
@@ -183,9 +183,11 @@ public Builder filteredBy(final CharacterPredicate... predicates) {
* @since 1.2
*/
public Builder selectFrom(final char... chars) {
- characterList = new ArrayList<>();
- for (final char c : chars) {
- characterList.add(c);
+ if(chars != null) {
Review Comment:
I got it. Yes. I see the error locally. Thank you
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org