You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "dan-s1 (via GitHub)" <gi...@apache.org> on 2025/07/18 14:56:31 UTC

[PR] NIFI-14766 Implemented PMD's ExhaustiveSwitchHasDefault, ImplicitSwitchFallThrough and TooFewBranchesForSwitch rules [nifi]

dan-s1 opened a new pull request, #10107:
URL: https://github.com/apache/nifi/pull/10107

   <!-- Licensed to the Apache Software Foundation (ASF) under one or more -->
   <!-- contributor license agreements.  See the NOTICE file distributed with -->
   <!-- this work for additional information regarding copyright ownership. -->
   <!-- The ASF licenses this file to You under the Apache License, Version 2.0 -->
   <!-- (the "License"); you may not use this file except in compliance with -->
   <!-- the License.  You may obtain a copy of the License at -->
   <!--     http://www.apache.org/licenses/LICENSE-2.0 -->
   <!-- Unless required by applicable law or agreed to in writing, software -->
   <!-- distributed under the License is distributed on an "AS IS" BASIS, -->
   <!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
   <!-- See the License for the specific language governing permissions and -->
   <!-- limitations under the License. -->
   
   # Summary
   
   [NIFI-14766](https://issues.apache.org/jira/browse/NIFI-14766)
   
   # Tracking
   
   Please complete the following tracking steps prior to pull request creation.
   
   ### Issue Tracking
   
   - [ ] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created
   
   ### Pull Request Tracking
   
   - [ ] Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-00000`
   - [ ] Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-00000`
   
   ### Pull Request Formatting
   
   - [ ] Pull Request based on current revision of the `main` branch
   - [ ] Pull Request refers to a feature branch with one commit containing changes
   
   # Verification
   
   Please indicate the verification steps performed prior to pull request creation.
   
   ### Build
   
   - [ ] Build completed using `mvn clean install -P contrib-check`
     - [ ] JDK 21
   
   ### Licensing
   
   - [ ] New dependencies are compatible with the [Apache License 2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html)
   - [ ] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
   
   ### Documentation
   
   - [ ] Documentation formatting appears as expected in rendered files
   


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


Re: [PR] NIFI-14766 Implemented PMD's ExhaustiveSwitchHasDefault, ImplicitSwitchFallThrough and TooFewBranchesForSwitch rules [nifi]

Posted by "mosermw (via GitHub)" <gi...@apache.org>.
mosermw commented on PR #10107:
URL: https://github.com/apache/nifi/pull/10107#issuecomment-3090757887

   I agree `minimumNumberCaseForASwitch` of 2 seems reasonable.  A switch with 1 case shouldn't be using switch at all :)


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


Re: [PR] NIFI-14766 Implemented PMD's ExhaustiveSwitchHasDefault, ImplicitSwitchFallThrough and TooFewBranchesForSwitch rules [nifi]

Posted by "mosermw (via GitHub)" <gi...@apache.org>.
mosermw commented on PR #10107:
URL: https://github.com/apache/nifi/pull/10107#issuecomment-3090640679

   Do we need the TooFewBranchesForSwitch rule?  It seems like the solution creates less readable code.


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


Re: [PR] NIFI-14766 Implemented PMD's ExhaustiveSwitchHasDefault, ImplicitSwitchFallThrough and TooFewBranchesForSwitch rules [nifi]

Posted by "dan-s1 (via GitHub)" <gi...@apache.org>.
dan-s1 commented on PR #10107:
URL: https://github.com/apache/nifi/pull/10107#issuecomment-3114255913

   @exceptionfactory All good! 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@nifi.apache.org

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


Re: [PR] NIFI-14766 Implemented PMD's ExhaustiveSwitchHasDefault, ImplicitSwitchFallThrough and TooFewBranchesForSwitch rules [nifi]

Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on PR #10107:
URL: https://github.com/apache/nifi/pull/10107#issuecomment-3090664648

   > Right now the default is 3 hence resulting in the opinionated rule. :).
   
   Thanks, I misread the default setting. Yes, changing to 2 sounds like it could work if it reduced the scope of changes. What do you think @mosermw?


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


Re: [PR] NIFI-14766 Implemented PMD's ExhaustiveSwitchHasDefault, ImplicitSwitchFallThrough and TooFewBranchesForSwitch rules [nifi]

Posted by "dan-s1 (via GitHub)" <gi...@apache.org>.
dan-s1 commented on PR #10107:
URL: https://github.com/apache/nifi/pull/10107#issuecomment-3090625168

   `./mvnw clean install -Pcontrib-check`


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


Re: [PR] NIFI-14766 Implemented PMD's ExhaustiveSwitchHasDefault, ImplicitSwitchFallThrough and TooFewBranchesForSwitch rules [nifi]

Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory merged PR #10107:
URL: https://github.com/apache/nifi/pull/10107


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


Re: [PR] NIFI-14766 Implemented PMD's ExhaustiveSwitchHasDefault, ImplicitSwitchFallThrough and TooFewBranchesForSwitch rules [nifi]

Posted by "mosermw (via GitHub)" <gi...@apache.org>.
mosermw commented on PR #10107:
URL: https://github.com/apache/nifi/pull/10107#issuecomment-3109400593

   > I wanted to double check whether the logic in these classes are correct or perhaps they need to have break statements. 
   > 
   > * org.apache.nifi.controller.serialization.AffectedComponentSet after line 550 there is no break statement.
   > * org.apache.nifi.processors.standard.ControlRate after line  280 there is no break statement.
   > * org.apache.nifi.processors.standard.TailFile after line 1034 there is no break statement.
   > * org.apache.nifi.authorization.StandardAuthorizableLookup after line 592 there is no break statement.
   > 
   > Please advise. Thanks!
   
   I had a look at these:
   
   - I think AffectedComponentSet is missing a break statement there. I'm not sure the case ever happens, or if it does happen then falling through has no negative effects, but I think a break is intended.
   - For ControlRate it appears the fallthrough is intentional, because the "Maximum Rate" property must be filled in when using either of DATA_RATE, FLOWFILE_RATE or ATTRIBUTE_RATE.  Having a comment there is good to make that clear.
   - After reading the javadoc for TailFile, it appears the fallthrough is intentional.  Having a comment there is good to make that clear.
   - For StandardAuthorizableLookup, I don't think it's possible to reach the end of the case, because a return or thrown exception is the only path out.  Having a break statement there probably won't hurt if it makes PMD happy.
   
   
   


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


Re: [PR] NIFI-14766 Implemented PMD's ExhaustiveSwitchHasDefault, ImplicitSwitchFallThrough and TooFewBranchesForSwitch rules [nifi]

Posted by "dan-s1 (via GitHub)" <gi...@apache.org>.
dan-s1 commented on PR #10107:
URL: https://github.com/apache/nifi/pull/10107#issuecomment-3097221915

   > I agree `minimumNumberCaseForASwitch` of 2 seems reasonable. A switch with 1 case shouldn't be using switch at all :)
   You would be surprised how many switch statements there were in the code base that only had one case statement.


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


Re: [PR] NIFI-14766 Implemented PMD's ExhaustiveSwitchHasDefault, ImplicitSwitchFallThrough and TooFewBranchesForSwitch rules [nifi]

Posted by "dan-s1 (via GitHub)" <gi...@apache.org>.
dan-s1 commented on PR #10107:
URL: https://github.com/apache/nifi/pull/10107#issuecomment-3114227436

   @exceptionfactory I was actually working to address @mosermw comments. What should I do with those changes?


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


Re: [PR] NIFI-14766 Implemented PMD's ExhaustiveSwitchHasDefault, ImplicitSwitchFallThrough and TooFewBranchesForSwitch rules [nifi]

Posted by "dan-s1 (via GitHub)" <gi...@apache.org>.
dan-s1 commented on PR #10107:
URL: https://github.com/apache/nifi/pull/10107#issuecomment-3090653653

   Would it make sense to set the property `minimumNumberCaseForASwitch` from the default value of 3 to 2?


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


Re: [PR] NIFI-14766 Implemented PMD's ExhaustiveSwitchHasDefault, ImplicitSwitchFallThrough and TooFewBranchesForSwitch rules [nifi]

Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on PR #10107:
URL: https://github.com/apache/nifi/pull/10107#issuecomment-3090661334

   > Would it make sense to set the property `minimumNumberCaseForASwitch` from the default value of 3 to 2 since most of the changes I have made are as a result of the switch accommodating enums which only have two values.
   
   If 3 aligns with current implementation, with just a few changes, that could be reasonable. If not, maybe 4.


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


Re: [PR] NIFI-14766 Implemented PMD's ExhaustiveSwitchHasDefault, ImplicitSwitchFallThrough and TooFewBranchesForSwitch rules [nifi]

Posted by "dan-s1 (via GitHub)" <gi...@apache.org>.
dan-s1 commented on PR #10107:
URL: https://github.com/apache/nifi/pull/10107#issuecomment-3097158476

   @exceptionfactory 
   I would like to address the original questions I had sent you by email  regarding the following classes which were flagged by PMD's ImplicitSwitchFallThrough rule.  I wanted to double check whether the logic in these classes are correct or perhaps they need to change.
   
   - org.apache.nifi.controller.serialization.AffectedComponentSet after line 550 there is no break statement.
   - org.apache.nifi.processors.standard.ControlRate after line  280 there is no break statement.
   - org.apache.nifi.processors.standard.RetryFlowFile after line 248 there is no break statement.
   - org.apache.nifi.processors.standard.TailFile after line 1034 there is no break statement.
   - org.apache.nifi.attribute.expression.language.evaluation.cast.WholeNumberCastEvaluator after line 72 there is  no break statement.
   - org.apache.nifi.attribute.expression.language.evaluation.cast.DecimalCastEvaluator after line 70 there is no break statement.
   - org.apache.nifi.attribute.expression.language.evaluation.cast.NumberCastEvaluator after line 77 there is no break statement.
   - org.apache.nifi.attribute.expression.language.evaluation.cast.WholeNumberCastEvaluator after line 72 there is  no break statement.
   - org.apache.nifi.authorization.StandardAuthorizableLookup after line 592 there is no break statement.
   


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


Re: [PR] NIFI-14766 Implemented PMD's ExhaustiveSwitchHasDefault, ImplicitSwitchFallThrough and TooFewBranchesForSwitch rules [nifi]

Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on PR #10107:
URL: https://github.com/apache/nifi/pull/10107#issuecomment-3114243540

   > @exceptionfactory I was actually working to address @mosermw comments. What should I do with those changes?
   
   Thanks @dan-s1, sorry for the misunderstanding. If you can open a new PR with those changes, that should be fine.


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


Re: [PR] NIFI-14766 Implemented PMD's ExhaustiveSwitchHasDefault, ImplicitSwitchFallThrough and TooFewBranchesForSwitch rules [nifi]

Posted by "dan-s1 (via GitHub)" <gi...@apache.org>.
dan-s1 commented on PR #10107:
URL: https://github.com/apache/nifi/pull/10107#issuecomment-3090484475

   @exceptionfactory Are there parts of the code which are not built when we build locally? Its weird as I built locally and did not have all these errors which I have seen the last few times.


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


Re: [PR] NIFI-14766 Implemented PMD's ExhaustiveSwitchHasDefault, ImplicitSwitchFallThrough and TooFewBranchesForSwitch rules [nifi]

Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on PR #10107:
URL: https://github.com/apache/nifi/pull/10107#issuecomment-3090650092

   > Do we need the TooFewBranchesForSwitch rule? It seems like the solution creates less readable code.
   
   I agree with @mosermw. I think this rule is a bit too opinionated for general purposes.


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


Re: [PR] NIFI-14766 Implemented PMD's ExhaustiveSwitchHasDefault, ImplicitSwitchFallThrough and TooFewBranchesForSwitch rules [nifi]

Posted by "dan-s1 (via GitHub)" <gi...@apache.org>.
dan-s1 commented on PR #10107:
URL: https://github.com/apache/nifi/pull/10107#issuecomment-3090662922

   Right now the default is 3 hence resulting in the opinionated rule.  :).


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


Re: [PR] NIFI-14766 Implemented PMD's ExhaustiveSwitchHasDefault, ImplicitSwitchFallThrough and TooFewBranchesForSwitch rules [nifi]

Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on PR #10107:
URL: https://github.com/apache/nifi/pull/10107#issuecomment-3090521213

   > @exceptionfactory Are there parts of the code which are not built when we build locally? Its weird as I built locally and did not have all these errors which I have seen the last few times.
   
   What command are you running for a local build? There are optional build profiles, and some integration tests, which are not enabled by default, but which are enabled in the GitHub build.


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


Re: [PR] NIFI-14766 Implemented PMD's ExhaustiveSwitchHasDefault, ImplicitSwitchFallThrough and TooFewBranchesForSwitch rules [nifi]

Posted by "dan-s1 (via GitHub)" <gi...@apache.org>.
dan-s1 commented on PR #10107:
URL: https://github.com/apache/nifi/pull/10107#issuecomment-3109448219

   @mosermw Thank you for commenting on this! It is much appreciated.


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