-
Notifications
You must be signed in to change notification settings - Fork 644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate quota limits to be non-negative in throttling policies #13059
base: master
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThis pull request introduces a new error code for handling invalid quota limits and enhances the validation process for throttle policies. A new error code, Changes
Suggested reviewers
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Nitpick comments (2)
components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/RestApiAdminUtils.java (2)
46-46
: Replace wildcard import for clarity.Consider importing only the specific classes you need instead of using the wildcard import
import java.util.*;
for better maintainability and clarity.
206-228
: Abstract duplicate negative checks for AI quota limit.While
validateAiQuotaLimit()
thoroughly checks each sub-field ofaiApiQuota
, you might unify these negative checks in a helper method or loop to reduce repetition. Also, ensure you handle a nullaiApiQuota
object.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/ExceptionCodes.java
(1 hunks)components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/ThrottlingApiServiceImpl.java
(3 hunks)components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/RestApiAdminUtils.java
(2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/ThrottlingApiServiceImpl.java (1)
components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/RestApiAdminUtils.java (1)
RestApiAdminUtils
(52-471)
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: build-product (2, group2)
- GitHub Check: build-product (4, group4)
- GitHub Check: build-product (3, group3)
- GitHub Check: build-product (1, group1)
- GitHub Check: run-benchmark-test
- GitHub Check: build-carbon
🔇 Additional comments (5)
components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/ExceptionCodes.java (1)
429-429
: Looks good - New error code for handling negative quota limits.This addition of
INVALID_QUOTA_LIMIT
error code is clean and follows the established pattern for error codes in the system. It will be used for validating that quota limits in throttling policies are non-negative values.components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/ThrottlingApiServiceImpl.java (3)
114-114
: Good addition of validation for Advanced throttling policy limit properties.This validation ensures that the quota limits in the Advanced throttling policy are non-negative before proceeding with policy creation, improving input validation.
308-308
: Good addition of validation for Application throttling policy limit properties.This validation ensures that the quota limits in the Application throttling policy are non-negative before proceeding with policy creation, improving input validation.
509-509
: Good addition of validation for Subscription throttling policy limit properties.This validation ensures that the quota limits in the Subscription throttling policy are non-negative before proceeding with policy creation, improving input validation.
components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/RestApiAdminUtils.java (1)
35-38
: Imports referencing new throttle policy DTOs look appropriate.These newly added imports correctly align with the new policy validation methods below.
private static void validateRequestCountLimit(ThrottleLimitDTO throttleLimitDTO) throws APIManagementException { | ||
if (throttleLimitDTO.getType().equals(ThrottleLimitDTO.TypeEnum.REQUESTCOUNTLIMIT)) { | ||
if (throttleLimitDTO.getRequestCount().getRequestCount() < 0) { | ||
throw new APIManagementException("Request count should be a non-negative value", | ||
ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, | ||
String.valueOf(throttleLimitDTO.getRequestCount().getRequestCount()))); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Check for null before using requestCount.
In validateRequestCountLimit()
, calling throttleLimitDTO.getRequestCount().getRequestCount()
can trigger an NPE if throttleLimitDTO.getRequestCount()
is null. Consider adding a null check to prevent runtime exceptions.
private static void validateBandwidthLimit(ThrottleLimitDTO throttleLimitDTO) throws APIManagementException { | ||
if (throttleLimitDTO.getType().equals(ThrottleLimitDTO.TypeEnum.BANDWIDTHLIMIT)) { | ||
if (throttleLimitDTO.getBandwidth().getDataAmount() < 0) { | ||
throw new APIManagementException("Bandwidth should be a non-negative value", | ||
ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, | ||
String.valueOf(throttleLimitDTO.getBandwidth().getDataAmount()))); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Check for null before using bandwidth.
Similar to the request count limit, ensure throttleLimitDTO.getBandwidth()
is non-null before accessing getDataAmount()
, preventing NPE in validateBandwidthLimit()
.
private static void validateEventCountLimit(ThrottleLimitDTO throttleLimitDTO) throws APIManagementException { | ||
if (throttleLimitDTO.getType().equals(ThrottleLimitDTO.TypeEnum.EVENTCOUNTLIMIT)) { | ||
if (throttleLimitDTO.getEventCount().getEventCount() < 0) { | ||
throw new APIManagementException("Event count should be a non-negative value", | ||
ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, | ||
String.valueOf(throttleLimitDTO.getEventCount().getEventCount()))); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Check for null before using eventCount.
In validateEventCountLimit()
, invoking throttleLimitDTO.getEventCount().getEventCount()
can fail if eventCount
is not provided. A null check is necessary to avoid potential crashes.
...admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/RestApiAdminUtils.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
♻️ Duplicate comments (1)
components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/RestApiAdminUtils.java (1)
148-178
:⚠️ Potential issueAdd null checks for defaultLimit to prevent NullPointerException
The method implements validation of throttle policy default limits, but it doesn't check if the retrieved
throttleLimitDTO
is null before using it, which could lead to NullPointerException.public static void validateThrottlePolicyDefaultLimitProperty(ThrottlePolicyDTO throttlePolicyDTO) throws APIManagementException { ThrottleLimitDTO throttleLimitDTO; if (throttlePolicyDTO instanceof AdvancedThrottlePolicyDTO) { + if (((AdvancedThrottlePolicyDTO) throttlePolicyDTO).getDefaultLimit() == null) { + throw new APIManagementException("Default limit cannot be null", + ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, "NULL_LIMIT")); + } throttleLimitDTO = ((AdvancedThrottlePolicyDTO) throttlePolicyDTO).getDefaultLimit(); validateRequestCountLimit(throttleLimitDTO); validateBandwidthLimit(throttleLimitDTO); } else if (throttlePolicyDTO instanceof ApplicationThrottlePolicyDTO) { + if (((ApplicationThrottlePolicyDTO) throttlePolicyDTO).getDefaultLimit() == null) { + throw new APIManagementException("Default limit cannot be null", + ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, "NULL_LIMIT")); + } throttleLimitDTO = ((ApplicationThrottlePolicyDTO) throttlePolicyDTO).getDefaultLimit(); validateRequestCountLimit(throttleLimitDTO); validateBandwidthLimit(throttleLimitDTO); if (((ApplicationThrottlePolicyDTO) throttlePolicyDTO).getBurstLimit() != null) { if (((ApplicationThrottlePolicyDTO) throttlePolicyDTO).getBurstLimit().getRateLimitCount() < 0) { throw new APIManagementException("Burst Control rate limit should be a non-negative value", ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, String.valueOf(throttleLimitDTO.getRequestCount().getRequestCount()))); } } } else if (throttlePolicyDTO instanceof SubscriptionThrottlePolicyDTO) { + if (((SubscriptionThrottlePolicyDTO) throttlePolicyDTO).getDefaultLimit() == null) { + throw new APIManagementException("Default limit cannot be null", + ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, "NULL_LIMIT")); + } throttleLimitDTO = ((SubscriptionThrottlePolicyDTO) throttlePolicyDTO).getDefaultLimit(); validateRequestCountLimit(throttleLimitDTO); validateBandwidthLimit(throttleLimitDTO); validateEventCountLimit(throttleLimitDTO); validateAiQuotaLimit(throttleLimitDTO); if (((SubscriptionThrottlePolicyDTO) throttlePolicyDTO).getRateLimitCount() < 0) { throw new APIManagementException("Rate limit count should be a non-negative value", ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, String.valueOf(throttleLimitDTO.getRequestCount().getRequestCount()))); } } }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/ExceptionCodes.java
(1 hunks)components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/ThrottlingApiServiceImpl.java
(3 hunks)components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/RestApiAdminUtils.java
(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/ExceptionCodes.java
- components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/ThrottlingApiServiceImpl.java
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: build-product (2, group2)
- GitHub Check: build-product (3, group3)
- GitHub Check: build-product (4, group4)
- GitHub Check: build-product (1, group1)
- GitHub Check: run-benchmark-test
- GitHub Check: build-carbon
🔇 Additional comments (3)
components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/RestApiAdminUtils.java (3)
180-188
: Check for null before using requestCountIn
validateRequestCountLimit()
, callingthrottleLimitDTO.getRequestCount().getRequestCount()
can trigger an NPE ifthrottleLimitDTO.getRequestCount()
is null. Consider adding a null check to prevent runtime exceptions.private static void validateRequestCountLimit(ThrottleLimitDTO throttleLimitDTO) throws APIManagementException { if (throttleLimitDTO.getType().equals(ThrottleLimitDTO.TypeEnum.REQUESTCOUNTLIMIT)) { + if (throttleLimitDTO.getRequestCount() == null) { + throw new APIManagementException("Request count cannot be null", + ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, "NULL_REQUEST_COUNT")); + } if (throttleLimitDTO.getRequestCount().getRequestCount() < 0) { throw new APIManagementException("Request count should be a non-negative value", ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, String.valueOf(throttleLimitDTO.getRequestCount().getRequestCount()))); } } }
190-198
: Check for null before using bandwidthSimilar to the request count limit, ensure
throttleLimitDTO.getBandwidth()
is non-null before accessinggetDataAmount()
, preventing NPE invalidateBandwidthLimit()
.private static void validateBandwidthLimit(ThrottleLimitDTO throttleLimitDTO) throws APIManagementException { if (throttleLimitDTO.getType().equals(ThrottleLimitDTO.TypeEnum.BANDWIDTHLIMIT)) { + if (throttleLimitDTO.getBandwidth() == null) { + throw new APIManagementException("Bandwidth cannot be null", + ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, "NULL_BANDWIDTH")); + } if (throttleLimitDTO.getBandwidth().getDataAmount() < 0) { throw new APIManagementException("Bandwidth should be a non-negative value", ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, String.valueOf(throttleLimitDTO.getBandwidth().getDataAmount()))); } } }
200-208
: Check for null before using eventCountIn
validateEventCountLimit()
, invokingthrottleLimitDTO.getEventCount().getEventCount()
can fail ifeventCount
is not provided. A null check is necessary to avoid potential crashes.private static void validateEventCountLimit(ThrottleLimitDTO throttleLimitDTO) throws APIManagementException { if (throttleLimitDTO.getType().equals(ThrottleLimitDTO.TypeEnum.EVENTCOUNTLIMIT)) { + if (throttleLimitDTO.getEventCount() == null) { + throw new APIManagementException("Event count cannot be null", + ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, "NULL_EVENT_COUNT")); + } if (throttleLimitDTO.getEventCount().getEventCount() < 0) { throw new APIManagementException("Event count should be a non-negative value", ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, String.valueOf(throttleLimitDTO.getEventCount().getEventCount()))); } } }
private static void validateAiQuotaLimit(ThrottleLimitDTO throttleLimitDTO) throws APIManagementException { | ||
if (throttleLimitDTO.getType().equals(ThrottleLimitDTO.TypeEnum.AIAPIQUOTALIMIT)) { | ||
List<String> paramNames = new ArrayList<>(); | ||
if (throttleLimitDTO.getAiApiQuota().getRequestCount() < 0) { | ||
paramNames.add("Request Count"); | ||
} | ||
if (throttleLimitDTO.getAiApiQuota().getTotalTokenCount() < 0) { | ||
paramNames.add("Total Token Count"); | ||
} | ||
if (throttleLimitDTO.getAiApiQuota().getPromptTokenCount() < 0) { | ||
paramNames.add("Prompt Token Count"); | ||
} | ||
if (throttleLimitDTO.getAiApiQuota().getCompletionTokenCount() < 0) { | ||
paramNames.add("Complete Token Count"); | ||
} | ||
|
||
if (!paramNames.isEmpty()) { | ||
throw new APIManagementException("AI quota limit should be a non-negative value", | ||
ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, | ||
String.join(",", paramNames))); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add null check for AI quota
The validateAiQuotaLimit()
method doesn't check if throttleLimitDTO.getAiApiQuota()
is null before accessing its methods, which could lead to a NullPointerException.
private static void validateAiQuotaLimit(ThrottleLimitDTO throttleLimitDTO) throws APIManagementException {
if (throttleLimitDTO.getType().equals(ThrottleLimitDTO.TypeEnum.AIAPIQUOTALIMIT)) {
+ if (throttleLimitDTO.getAiApiQuota() == null) {
+ throw new APIManagementException("AI API quota cannot be null",
+ ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, "NULL_AI_QUOTA"));
+ }
List<String> paramNames = new ArrayList<>();
if (throttleLimitDTO.getAiApiQuota().getRequestCount() < 0) {
paramNames.add("Request Count");
}
if (throttleLimitDTO.getAiApiQuota().getTotalTokenCount() < 0) {
paramNames.add("Total Token Count");
}
if (throttleLimitDTO.getAiApiQuota().getPromptTokenCount() < 0) {
paramNames.add("Prompt Token Count");
}
if (throttleLimitDTO.getAiApiQuota().getCompletionTokenCount() < 0) {
paramNames.add("Complete Token Count");
}
if (!paramNames.isEmpty()) {
throw new APIManagementException("AI quota limit should be a non-negative value",
ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT,
String.join(",", paramNames)));
}
}
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
private static void validateAiQuotaLimit(ThrottleLimitDTO throttleLimitDTO) throws APIManagementException { | |
if (throttleLimitDTO.getType().equals(ThrottleLimitDTO.TypeEnum.AIAPIQUOTALIMIT)) { | |
List<String> paramNames = new ArrayList<>(); | |
if (throttleLimitDTO.getAiApiQuota().getRequestCount() < 0) { | |
paramNames.add("Request Count"); | |
} | |
if (throttleLimitDTO.getAiApiQuota().getTotalTokenCount() < 0) { | |
paramNames.add("Total Token Count"); | |
} | |
if (throttleLimitDTO.getAiApiQuota().getPromptTokenCount() < 0) { | |
paramNames.add("Prompt Token Count"); | |
} | |
if (throttleLimitDTO.getAiApiQuota().getCompletionTokenCount() < 0) { | |
paramNames.add("Complete Token Count"); | |
} | |
if (!paramNames.isEmpty()) { | |
throw new APIManagementException("AI quota limit should be a non-negative value", | |
ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, | |
String.join(",", paramNames))); | |
} | |
} | |
} | |
private static void validateAiQuotaLimit(ThrottleLimitDTO throttleLimitDTO) throws APIManagementException { | |
if (throttleLimitDTO.getType().equals(ThrottleLimitDTO.TypeEnum.AIAPIQUOTALIMIT)) { | |
if (throttleLimitDTO.getAiApiQuota() == null) { | |
throw new APIManagementException("AI API quota cannot be null", | |
ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, "NULL_AI_QUOTA")); | |
} | |
List<String> paramNames = new ArrayList<>(); | |
if (throttleLimitDTO.getAiApiQuota().getRequestCount() < 0) { | |
paramNames.add("Request Count"); | |
} | |
if (throttleLimitDTO.getAiApiQuota().getTotalTokenCount() < 0) { | |
paramNames.add("Total Token Count"); | |
} | |
if (throttleLimitDTO.getAiApiQuota().getPromptTokenCount() < 0) { | |
paramNames.add("Prompt Token Count"); | |
} | |
if (throttleLimitDTO.getAiApiQuota().getCompletionTokenCount() < 0) { | |
paramNames.add("Complete Token Count"); | |
} | |
if (!paramNames.isEmpty()) { | |
throw new APIManagementException("AI quota limit should be a non-negative value", | |
ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, | |
String.join(",", paramNames))); | |
} | |
} | |
} |
if (((SubscriptionThrottlePolicyDTO) throttlePolicyDTO).getRateLimitCount() < 0) { | ||
throw new APIManagementException("Rate limit count should be a non-negative value", | ||
ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, | ||
String.valueOf(throttleLimitDTO.getRequestCount().getRequestCount()))); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix potential NullPointerException in rate limit validation
When validating the rate limit count, the code references throttleLimitDTO.getRequestCount().getRequestCount()
in the error code, but if the current throttle limit type is not REQUESTCOUNTLIMIT
, this could cause a NullPointerException.
if (((SubscriptionThrottlePolicyDTO) throttlePolicyDTO).getRateLimitCount() < 0) {
throw new APIManagementException("Rate limit count should be a non-negative value",
ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT,
- String.valueOf(throttleLimitDTO.getRequestCount().getRequestCount())));
+ String.valueOf(((SubscriptionThrottlePolicyDTO) throttlePolicyDTO).getRateLimitCount())));
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if (((SubscriptionThrottlePolicyDTO) throttlePolicyDTO).getRateLimitCount() < 0) { | |
throw new APIManagementException("Rate limit count should be a non-negative value", | |
ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, | |
String.valueOf(throttleLimitDTO.getRequestCount().getRequestCount()))); | |
} | |
if (((SubscriptionThrottlePolicyDTO) throttlePolicyDTO).getRateLimitCount() < 0) { | |
throw new APIManagementException("Rate limit count should be a non-negative value", | |
ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, | |
String.valueOf(((SubscriptionThrottlePolicyDTO) throttlePolicyDTO).getRateLimitCount()))); | |
} |
if (((ApplicationThrottlePolicyDTO) throttlePolicyDTO).getBurstLimit().getRateLimitCount() < 0) { | ||
throw new APIManagementException("Burst Control rate limit should be a non-negative value", | ||
ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, | ||
String.valueOf(throttleLimitDTO.getRequestCount().getRequestCount()))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix incorrect error message parameter
In the exception thrown for negative burst limit, the error message references throttleLimitDTO.getRequestCount().getRequestCount()
which may not be related to the burst limit being validated and could cause NullPointerException if request count is null.
throw new APIManagementException("Burst Control rate limit should be a non-negative value",
ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT,
- String.valueOf(throttleLimitDTO.getRequestCount().getRequestCount())));
+ String.valueOf(((ApplicationThrottlePolicyDTO) throttlePolicyDTO).getBurstLimit().getRateLimitCount())));
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
String.valueOf(throttleLimitDTO.getRequestCount().getRequestCount()))); | |
throw new APIManagementException("Burst Control rate limit should be a non-negative value", | |
ExceptionCodes.from(ExceptionCodes.INVALID_QUOTA_LIMIT, | |
String.valueOf(((ApplicationThrottlePolicyDTO) throttlePolicyDTO).getBurstLimit().getRateLimitCount()))); |
Backend fix for wso2/api-manager#3764