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/24 21:17:55 UTC
[PR] NIFI-14787 Implemented code improvements to avoid PMD's ImplicitSwitchFallThrough rule. [nifi]
dan-s1 opened a new pull request, #10134:
URL: https://github.com/apache/nifi/pull/10134
<!-- 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-14787](https://issues.apache.org/jira/browse/NIFI-14787)
# 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-14787 Implemented code improvements to avoid PMD's ImplicitSwitchFallThrough rule. [nifi]
Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on code in PR #10134:
URL: https://github.com/apache/nifi/pull/10134#discussion_r2231137704
##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/authorization/StandardAuthorizableLookup.java:
##########
@@ -569,28 +569,8 @@ public Authorizable getAuthorizableFromResource(final String resource) {
case DataTransfer:
case ProvenanceData:
case Operation:
-
- // get the resource type
- final String baseResource = StringUtils.substringAfter(resource, resourceType.getValue());
- final ResourceType baseResourceType = ResourceType.fromRawValue(baseResource);
-
- if (baseResourceType == null) {
- throw new ResourceNotFoundException("Unrecognized base resource: " + resource);
- }
-
- switch (resourceType) {
- case Policy:
- return new AccessPolicyAuthorizable(getAccessPolicy(baseResourceType, resource));
- case Data:
- return new DataAuthorizable(getAccessPolicy(baseResourceType, resource));
- case DataTransfer:
- return new DataTransferAuthorizable(getAccessPolicy(baseResourceType, resource));
- case ProvenanceData:
- return new ProvenanceDataAuthorizable(getAccessPolicy(baseResourceType, resource));
- case Operation:
- return new OperationAuthorizable(getAccessPolicy(baseResourceType, resource));
- }
- // fallthrough
+ final Authorizable authorizable = handleResourceTypeContainingOtherResourceType(resource, resourceType);
+ return authorizable;
Review Comment:
There are different preferences, I actually prefer the one-line return, others prefer it declared. In general I would ignore it, but I highlighted it here since there is nothing else in the code block.
--
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-14787 Implemented code improvements to avoid PMD's ImplicitSwitchFallThrough rule. [nifi]
Posted by "dan-s1 (via GitHub)" <gi...@apache.org>.
dan-s1 commented on code in PR #10134:
URL: https://github.com/apache/nifi/pull/10134#discussion_r2231090580
##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/authorization/StandardAuthorizableLookup.java:
##########
@@ -628,6 +608,25 @@ public Authorizable getAuthorizableFromResource(final String resource) {
}
}
+ private Authorizable handleResourceTypeContainingOtherResourceType(final String resource, final ResourceType resourceType) {
+ // get the resource type
+ final String baseResource = StringUtils.substringAfter(resource, resourceType.getValue());
+ final ResourceType baseResourceType = ResourceType.fromRawValue(baseResource);
+
+ if (baseResourceType == null) {
+ throw new ResourceNotFoundException("Unrecognized base resource: " + resource);
+ }
+
+ return switch (resourceType) {
+ case Policy -> new AccessPolicyAuthorizable(getAccessPolicy(baseResourceType, resource));
+ case Data -> new DataAuthorizable(getAccessPolicy(baseResourceType, resource));
+ case DataTransfer -> new DataTransferAuthorizable(getAccessPolicy(baseResourceType, resource));
+ case ProvenanceData -> new ProvenanceDataAuthorizable(getAccessPolicy(baseResourceType, resource));
+ case Operation -> new OperationAuthorizable(getAccessPolicy(baseResourceType, resource));
+ default -> null;
Review Comment:
It did not. I initially did not have a `default` and the compiler complained that something has to be returned so I put a return null after the switch statement. Then Intellij suggested to refactor to an enhanced switch statement whereby it inserted the default with a return of null. Honestly this method should never be used except for in the five cases where a resource type can have another resource type so the default should never be reached.
--
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-14787 Implemented code improvements to avoid PMD's ImplicitSwitchFallThrough rule. [nifi]
Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory merged PR #10134:
URL: https://github.com/apache/nifi/pull/10134
--
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-14787 Implemented code improvements to avoid PMD's ImplicitSwitchFallThrough rule. [nifi]
Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on code in PR #10134:
URL: https://github.com/apache/nifi/pull/10134#discussion_r2231062450
##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/authorization/StandardAuthorizableLookup.java:
##########
@@ -569,28 +569,8 @@ public Authorizable getAuthorizableFromResource(final String resource) {
case DataTransfer:
case ProvenanceData:
case Operation:
-
- // get the resource type
- final String baseResource = StringUtils.substringAfter(resource, resourceType.getValue());
- final ResourceType baseResourceType = ResourceType.fromRawValue(baseResource);
-
- if (baseResourceType == null) {
- throw new ResourceNotFoundException("Unrecognized base resource: " + resource);
- }
-
- switch (resourceType) {
- case Policy:
- return new AccessPolicyAuthorizable(getAccessPolicy(baseResourceType, resource));
- case Data:
- return new DataAuthorizable(getAccessPolicy(baseResourceType, resource));
- case DataTransfer:
- return new DataTransferAuthorizable(getAccessPolicy(baseResourceType, resource));
- case ProvenanceData:
- return new ProvenanceDataAuthorizable(getAccessPolicy(baseResourceType, resource));
- case Operation:
- return new OperationAuthorizable(getAccessPolicy(baseResourceType, resource));
- }
- // fallthrough
+ final Authorizable authorizable = handleResourceTypeContainingOtherResourceType(resource, resourceType);
+ return authorizable;
Review Comment:
It looks like this could be collapsed into a single line with a return.
##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/authorization/StandardAuthorizableLookup.java:
##########
@@ -628,6 +608,25 @@ public Authorizable getAuthorizableFromResource(final String resource) {
}
}
+ private Authorizable handleResourceTypeContainingOtherResourceType(final String resource, final ResourceType resourceType) {
+ // get the resource type
+ final String baseResource = StringUtils.substringAfter(resource, resourceType.getValue());
+ final ResourceType baseResourceType = ResourceType.fromRawValue(baseResource);
+
+ if (baseResourceType == null) {
+ throw new ResourceNotFoundException("Unrecognized base resource: " + resource);
+ }
+
+ return switch (resourceType) {
+ case Policy -> new AccessPolicyAuthorizable(getAccessPolicy(baseResourceType, resource));
+ case Data -> new DataAuthorizable(getAccessPolicy(baseResourceType, resource));
+ case DataTransfer -> new DataTransferAuthorizable(getAccessPolicy(baseResourceType, resource));
+ case ProvenanceData -> new ProvenanceDataAuthorizable(getAccessPolicy(baseResourceType, resource));
+ case Operation -> new OperationAuthorizable(getAccessPolicy(baseResourceType, resource));
+ default -> null;
Review Comment:
Did the previous fall through case return `null` as well? It seems like this should throw an exception.
--
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-14787 Implemented code improvements to avoid PMD's ImplicitSwitchFallThrough rule. [nifi]
Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on code in PR #10134:
URL: https://github.com/apache/nifi/pull/10134#discussion_r2231141402
##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/authorization/StandardAuthorizableLookup.java:
##########
@@ -628,6 +608,25 @@ public Authorizable getAuthorizableFromResource(final String resource) {
}
}
+ private Authorizable handleResourceTypeContainingOtherResourceType(final String resource, final ResourceType resourceType) {
+ // get the resource type
+ final String baseResource = StringUtils.substringAfter(resource, resourceType.getValue());
+ final ResourceType baseResourceType = ResourceType.fromRawValue(baseResource);
+
+ if (baseResourceType == null) {
+ throw new ResourceNotFoundException("Unrecognized base resource: " + resource);
+ }
+
+ return switch (resourceType) {
+ case Policy -> new AccessPolicyAuthorizable(getAccessPolicy(baseResourceType, resource));
+ case Data -> new DataAuthorizable(getAccessPolicy(baseResourceType, resource));
+ case DataTransfer -> new DataTransferAuthorizable(getAccessPolicy(baseResourceType, resource));
+ case ProvenanceData -> new ProvenanceDataAuthorizable(getAccessPolicy(baseResourceType, resource));
+ case Operation -> new OperationAuthorizable(getAccessPolicy(baseResourceType, resource));
+ default -> null;
Review Comment:
Thanks, I was thinking it was a rare scenario. It seems like throwing an `IllegalArgumentException` would help clarify that this should not happen, what do you think?
--
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-14787 Implemented code improvements to avoid PMD's ImplicitSwitchFallThrough rule. [nifi]
Posted by "dan-s1 (via GitHub)" <gi...@apache.org>.
dan-s1 commented on code in PR #10134:
URL: https://github.com/apache/nifi/pull/10134#discussion_r2231090580
##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/authorization/StandardAuthorizableLookup.java:
##########
@@ -628,6 +608,25 @@ public Authorizable getAuthorizableFromResource(final String resource) {
}
}
+ private Authorizable handleResourceTypeContainingOtherResourceType(final String resource, final ResourceType resourceType) {
+ // get the resource type
+ final String baseResource = StringUtils.substringAfter(resource, resourceType.getValue());
+ final ResourceType baseResourceType = ResourceType.fromRawValue(baseResource);
+
+ if (baseResourceType == null) {
+ throw new ResourceNotFoundException("Unrecognized base resource: " + resource);
+ }
+
+ return switch (resourceType) {
+ case Policy -> new AccessPolicyAuthorizable(getAccessPolicy(baseResourceType, resource));
+ case Data -> new DataAuthorizable(getAccessPolicy(baseResourceType, resource));
+ case DataTransfer -> new DataTransferAuthorizable(getAccessPolicy(baseResourceType, resource));
+ case ProvenanceData -> new ProvenanceDataAuthorizable(getAccessPolicy(baseResourceType, resource));
+ case Operation -> new OperationAuthorizable(getAccessPolicy(baseResourceType, resource));
+ default -> null;
Review Comment:
It did not. I initially did not have a `default` and the compiler complained that something has to be returned so I put a return null after the switch statement. Then Intellij suggested to refactor to an enhanced switch statement whereby it inserted the default with a return of null. Honestly this method should never be used except for in the five cases where a resource type can have another resource type so the default should never be reached. Its only there to make the compiler 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-14787 Implemented code improvements to avoid PMD's ImplicitSwitchFallThrough rule. [nifi]
Posted by "dan-s1 (via GitHub)" <gi...@apache.org>.
dan-s1 commented on code in PR #10134:
URL: https://github.com/apache/nifi/pull/10134#discussion_r2231082360
##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/authorization/StandardAuthorizableLookup.java:
##########
@@ -569,28 +569,8 @@ public Authorizable getAuthorizableFromResource(final String resource) {
case DataTransfer:
case ProvenanceData:
case Operation:
-
- // get the resource type
- final String baseResource = StringUtils.substringAfter(resource, resourceType.getValue());
- final ResourceType baseResourceType = ResourceType.fromRawValue(baseResource);
-
- if (baseResourceType == null) {
- throw new ResourceNotFoundException("Unrecognized base resource: " + resource);
- }
-
- switch (resourceType) {
- case Policy:
- return new AccessPolicyAuthorizable(getAccessPolicy(baseResourceType, resource));
- case Data:
- return new DataAuthorizable(getAccessPolicy(baseResourceType, resource));
- case DataTransfer:
- return new DataTransferAuthorizable(getAccessPolicy(baseResourceType, resource));
- case ProvenanceData:
- return new ProvenanceDataAuthorizable(getAccessPolicy(baseResourceType, resource));
- case Operation:
- return new OperationAuthorizable(getAccessPolicy(baseResourceType, resource));
- }
- // fallthrough
+ final Authorizable authorizable = handleResourceTypeContainingOtherResourceType(resource, resourceType);
+ return authorizable;
Review Comment:
Sure I can do that although from past reviews I thought you seem to prefer having a variable declared.
--
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