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 2021/01/04 18:34:22 UTC

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

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