You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2020/11/11 20:49:34 UTC

[GitHub] [nifi] ottobackwards opened a new pull request #4656: NIFI-7995 add null check before validating ParameterContexts

ottobackwards opened a new pull request #4656:
URL: https://github.com/apache/nifi/pull/4656


   Thank you for submitting a contribution to Apache NiFi.
   
   Please provide a short description of the PR here:
   
   #### Description of PR
   
   _Enables X functionality; fixes bug NIFI-YYYY._
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced 
        in the commit message?
   
   - [ ] Does your PR title start with **NIFI-XXXX** where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically `main`)?
   
   - [ ] Is your initial contribution a single, squashed commit? _Additional commits in response to PR reviewer feedback should be made on this branch and pushed to allow change tracking. Do not `squash` or use `--force` when pushing to allow for clean monitoring of changes._
   
   ### For code changes:
   - [ ] Have you ensured that the full suite of tests is executed via `mvn -Pcontrib-check clean install` at the root `nifi` folder?
   - [ ] Have you written or updated unit tests to verify your changes?
   - [ ] Have you verified that the full build is successful on JDK 8?
   - [ ] Have you verified that the full build is successful on JDK 11?
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? 
   - [ ] If applicable, have you updated the `LICENSE` file, including the main `LICENSE` file under `nifi-assembly`?
   - [ ] If applicable, have you updated the `NOTICE` file, including the main `NOTICE` file found under `nifi-assembly`?
   - [ ] If adding new Properties, have you added `.displayName` in addition to .name (programmatic access) for each of the new properties?
   
   ### For documentation related changes:
   - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
   
   ### Note:
   Please ensure that once the PR is submitted, you check GitHub Actions CI for build issues and submit an update to your PR as soon as possible.
   


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] ottobackwards commented on a change in pull request #4656: NIFI-7995 add null check before validating ParameterContexts

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on a change in pull request #4656:
URL: https://github.com/apache/nifi/pull/4656#discussion_r526088956



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ParameterContextResource.java
##########
@@ -400,11 +400,14 @@ public Response submitParameterContextUpdate(
     }
 
     private void validateParameterNames(final ParameterContextDTO parameterContextDto) {
-        for (final ParameterEntity entity : parameterContextDto.getParameters()) {
-            final String parameterName = entity.getParameter().getName();
-            if (!isLegalParameterName(parameterName)) {
-                throw new IllegalArgumentException("Request contains an illegal Parameter Name (" + parameterName + "). Parameter names may only include letters, numbers, spaces, and the special " +
-                    "characters .-_");
+        if (parameterContextDto.getParameters() != null) {

Review comment:
       ok, so the parameters are not marked as being required
   
   ```java
   @ApiModelProperty("The Parameters for the Parameter Context")
       public Set<ParameterEntity> getParameters() {
           return parameters;
       }
   ```
   
   So I think that throwing here is against the openapi spec and the contract in general.
   I'm not sure if chaffelson found this because of how openapi generated the code or not, but I don't think throwing here is right based on that.
   




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] ottobackwards commented on a change in pull request #4656: NIFI-7995 add null check before validating ParameterContexts

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on a change in pull request #4656:
URL: https://github.com/apache/nifi/pull/4656#discussion_r551536261



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ParameterContextResource.java
##########
@@ -400,11 +400,14 @@ public Response submitParameterContextUpdate(
     }
 
     private void validateParameterNames(final ParameterContextDTO parameterContextDto) {
-        for (final ParameterEntity entity : parameterContextDto.getParameters()) {
-            final String parameterName = entity.getParameter().getName();
-            if (!isLegalParameterName(parameterName)) {
-                throw new IllegalArgumentException("Request contains an illegal Parameter Name (" + parameterName + "). Parameter names may only include letters, numbers, spaces, and the special " +
-                    "characters .-_");
+        if (parameterContextDto.getParameters() != null) {

Review comment:
       Couldn't we just make the getParameters call return an empty list if null or something and just change that spot?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] ottobackwards commented on a change in pull request #4656: NIFI-7995 add null check before validating ParameterContexts

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on a change in pull request #4656:
URL: https://github.com/apache/nifi/pull/4656#discussion_r525355265



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ParameterContextResource.java
##########
@@ -400,11 +400,14 @@ public Response submitParameterContextUpdate(
     }
 
     private void validateParameterNames(final ParameterContextDTO parameterContextDto) {
-        for (final ParameterEntity entity : parameterContextDto.getParameters()) {
-            final String parameterName = entity.getParameter().getName();
-            if (!isLegalParameterName(parameterName)) {
-                throw new IllegalArgumentException("Request contains an illegal Parameter Name (" + parameterName + "). Parameter names may only include letters, numbers, spaces, and the special " +
-                    "characters .-_");
+        if (parameterContextDto.getParameters() != null) {

Review comment:
       I don't know enough about the api.  It doesn't seem that there is a check that there _are_ parameters at all elsewhere.
   Who is the sme?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] ottobackwards commented on a change in pull request #4656: NIFI-7995 add null check before validating ParameterContexts

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on a change in pull request #4656:
URL: https://github.com/apache/nifi/pull/4656#discussion_r551536622



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ParameterContextResource.java
##########
@@ -400,11 +400,14 @@ public Response submitParameterContextUpdate(
     }
 
     private void validateParameterNames(final ParameterContextDTO parameterContextDto) {
-        for (final ParameterEntity entity : parameterContextDto.getParameters()) {
-            final String parameterName = entity.getParameter().getName();
-            if (!isLegalParameterName(parameterName)) {
-                throw new IllegalArgumentException("Request contains an illegal Parameter Name (" + parameterName + "). Parameter names may only include letters, numbers, spaces, and the special " +
-                    "characters .-_");
+        if (parameterContextDto.getParameters() != null) {

Review comment:
       again, the the api doesn't have it as required, so accepting null i think is correct.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] github-actions[bot] commented on pull request #4656: NIFI-7995 add null check before validating ParameterContexts

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #4656:
URL: https://github.com/apache/nifi/pull/4656#issuecomment-877516951


   We're marking this PR as stale due to lack of updates in the past few months. If after another couple of weeks the stale label has not been removed this PR will be closed. This stale marker and eventual auto close does not indicate a judgement of the PR just lack of reviewer bandwidth and helps us keep the PR queue more manageable.  If you would like this PR re-opened you can do so and a committer can remove the stale tag.  Or you can open a new PR.  Try to help review other PRs to increase PR review bandwidth which in turn helps yours.


-- 
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@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] pvillard31 commented on a change in pull request #4656: NIFI-7995 add null check before validating ParameterContexts

Posted by GitBox <gi...@apache.org>.
pvillard31 commented on a change in pull request #4656:
URL: https://github.com/apache/nifi/pull/4656#discussion_r525599700



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ParameterContextResource.java
##########
@@ -400,11 +400,14 @@ public Response submitParameterContextUpdate(
     }
 
     private void validateParameterNames(final ParameterContextDTO parameterContextDto) {
-        for (final ParameterEntity entity : parameterContextDto.getParameters()) {
-            final String parameterName = entity.getParameter().getName();
-            if (!isLegalParameterName(parameterName)) {
-                throw new IllegalArgumentException("Request contains an illegal Parameter Name (" + parameterName + "). Parameter names may only include letters, numbers, spaces, and the special " +
-                    "characters .-_");
+        if (parameterContextDto.getParameters() != null) {

Review comment:
       I'd vote for something like
   ````java
   throw new IllegalArgumentException("Parameter Context must define at least one parameter.");
   ````




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] Chaffelson commented on a change in pull request #4656: NIFI-7995 add null check before validating ParameterContexts

Posted by GitBox <gi...@apache.org>.
Chaffelson commented on a change in pull request #4656:
URL: https://github.com/apache/nifi/pull/4656#discussion_r526250463



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ParameterContextResource.java
##########
@@ -400,11 +400,14 @@ public Response submitParameterContextUpdate(
     }
 
     private void validateParameterNames(final ParameterContextDTO parameterContextDto) {
-        for (final ParameterEntity entity : parameterContextDto.getParameters()) {
-            final String parameterName = entity.getParameter().getName();
-            if (!isLegalParameterName(parameterName)) {
-                throw new IllegalArgumentException("Request contains an illegal Parameter Name (" + parameterName + "). Parameter names may only include letters, numbers, spaces, and the special " +
-                    "characters .-_");
+        if (parameterContextDto.getParameters() != null) {

Review comment:
       Parameters should not be required when creating a Parameter context. Currently you are expected to provide an empty list object, but it throws an NPE if parameters = null.
   Either we should throw a reasonable error if the Parameters field is anything other than expected (rather than an NPE), or accept a null as if it was the empty list.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] github-actions[bot] closed pull request #4656: NIFI-7995 add null check before validating ParameterContexts

Posted by GitBox <gi...@apache.org>.
github-actions[bot] closed pull request #4656:
URL: https://github.com/apache/nifi/pull/4656


   


-- 
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@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] pvillard31 commented on a change in pull request #4656: NIFI-7995 add null check before validating ParameterContexts

Posted by GitBox <gi...@apache.org>.
pvillard31 commented on a change in pull request #4656:
URL: https://github.com/apache/nifi/pull/4656#discussion_r524415708



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ParameterContextResource.java
##########
@@ -400,11 +400,14 @@ public Response submitParameterContextUpdate(
     }
 
     private void validateParameterNames(final ParameterContextDTO parameterContextDto) {
-        for (final ParameterEntity entity : parameterContextDto.getParameters()) {
-            final String parameterName = entity.getParameter().getName();
-            if (!isLegalParameterName(parameterName)) {
-                throw new IllegalArgumentException("Request contains an illegal Parameter Name (" + parameterName + "). Parameter names may only include letters, numbers, spaces, and the special " +
-                    "characters .-_");
+        if (parameterContextDto.getParameters() != null) {

Review comment:
       Do we want to throw IllegalArgumentException if it's null? 




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] ottobackwards commented on pull request #4656: NIFI-7995 add null check before validating ParameterContexts

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on pull request #4656:
URL: https://github.com/apache/nifi/pull/4656#issuecomment-754006853


   Happy New Year!


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] markap14 commented on a change in pull request #4656: NIFI-7995 add null check before validating ParameterContexts

Posted by GitBox <gi...@apache.org>.
markap14 commented on a change in pull request #4656:
URL: https://github.com/apache/nifi/pull/4656#discussion_r551492094



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ParameterContextResource.java
##########
@@ -400,11 +400,14 @@ public Response submitParameterContextUpdate(
     }
 
     private void validateParameterNames(final ParameterContextDTO parameterContextDto) {
-        for (final ParameterEntity entity : parameterContextDto.getParameters()) {
-            final String parameterName = entity.getParameter().getName();
-            if (!isLegalParameterName(parameterName)) {
-                throw new IllegalArgumentException("Request contains an illegal Parameter Name (" + parameterName + "). Parameter names may only include letters, numbers, spaces, and the special " +
-                    "characters .-_");
+        if (parameterContextDto.getParameters() != null) {

Review comment:
       So looking through the codebase at where `ParameterContextDTO.getParameters()` is called, about 50% of the time, we check if the value is `null`, and 50% of the time, we would throw a `NullPointerException`, unfortunately. This is one of those awkward coding situation, IMO, because *generally* I don't believe that code should return `null` values for collections - they should return an empty collection. But with DTO's, we generally want to return exactly what was given to it - there should be no logic such as "if null, use empty collection".
   
   So I think either is perfectly acceptable. We can either say that the value MUST be populated and throw an IllegalArgumentException if it's not. OR we can say it's OK for that to be null, but in that situation we need to update everywhere in the code that looks at `ParameterContextDTO.getParameters()` - not just this Resource. I think I would lean toward the latter - allow a `null` value and just ensure that we always handle it properly. We should be lenient in what we permit.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] ottobackwards commented on a change in pull request #4656: NIFI-7995 add null check before validating ParameterContexts

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on a change in pull request #4656:
URL: https://github.com/apache/nifi/pull/4656#discussion_r526061414



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ParameterContextResource.java
##########
@@ -400,11 +400,14 @@ public Response submitParameterContextUpdate(
     }
 
     private void validateParameterNames(final ParameterContextDTO parameterContextDto) {
-        for (final ParameterEntity entity : parameterContextDto.getParameters()) {
-            final String parameterName = entity.getParameter().getName();
-            if (!isLegalParameterName(parameterName)) {
-                throw new IllegalArgumentException("Request contains an illegal Parameter Name (" + parameterName + "). Parameter names may only include letters, numbers, spaces, and the special " +
-                    "characters .-_");
+        if (parameterContextDto.getParameters() != null) {

Review comment:
       ok 




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] ottobackwards commented on a change in pull request #4656: NIFI-7995 add null check before validating ParameterContexts

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on a change in pull request #4656:
URL: https://github.com/apache/nifi/pull/4656#discussion_r526061624



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ParameterContextResource.java
##########
@@ -400,11 +400,14 @@ public Response submitParameterContextUpdate(
     }
 
     private void validateParameterNames(final ParameterContextDTO parameterContextDto) {
-        for (final ParameterEntity entity : parameterContextDto.getParameters()) {
-            final String parameterName = entity.getParameter().getName();
-            if (!isLegalParameterName(parameterName)) {
-                throw new IllegalArgumentException("Request contains an illegal Parameter Name (" + parameterName + "). Parameter names may only include letters, numbers, spaces, and the special " +
-                    "characters .-_");
+        if (parameterContextDto.getParameters() != null) {

Review comment:
       Is there a way that needs to be expressed in the OpenAPI or the annotations?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] ottobackwards commented on pull request #4656: NIFI-7995 add null check before validating ParameterContexts

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on pull request #4656:
URL: https://github.com/apache/nifi/pull/4656#issuecomment-796747593


   wakey wakey


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org