Skip to content

Conversation

yitingb
Copy link
Member

@yitingb yitingb commented Apr 30, 2025

Issue #, if available:

Description of changes:
Ignoring cases and white spaces
Why is this change necessary:

How was this change tested:

Any additional information or context required to review the change:

Checklist:

  • Updated the README if applicable
  • Updated or added new unit tests
  • Updated or added new integration tests
  • Updated or added new end-to-end tests

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Throwable cause = e;
while (cause != null) {
if (cause instanceof SocketException && "Connection reset".equals(cause.getMessage())) {
if (cause instanceof SocketException && "connection reset".contains(cause.getMessage().toLowerCase())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.

This code checks the status message of the exception instead of the status itself. You could help improve backwards compatibility by checking the error code, which is less likely to change over time.

Throwable cause = e;
while (cause != null) {
if (cause instanceof SocketException && "Connection reset".equals(cause.getMessage())) {
if (cause instanceof SocketException && "connection reset".contains(cause.getMessage().toLowerCase())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.

toLowerCase

The parameterless versions of String.toLowerCase() and String.toUpperCase() use the default locale of the JVM when transforming strings. This can have unintended results, including difficult-to-debug transient failures because case mapping differs based on locale.

Even if you aren’t writing code for a user experience that’s displayed to a customer, system internal code often uses case folding to normalize strings for comparison.
Not doing so can missing locale lead to errors when running on systems that are configured to use a different system locale. This can include developer desktops or build servers (not just your fleet hosts): many hours have been spent debugging errors that only occur on a specific machine due to its locale configuration.

Recommended solutions:

Always pass in a Locale.

Language or locale-dependent processing:

Get the locale from the platform, use the language of the content, or configure it in your code and pass that to the method.

String firstName = "Ichabod"; 
Locale locale = // Where you obtain the locale from is platform dependent
String lowerCaseFirstName = firstName.toLowerCase(locale);

Internal processing that isn’t locale-dependent:

Example: S3 bucket name

Always specify the language/country-neutral locale Locale.ROOT.

String imgTag = "IMG"; 
if ("img".equals(imgTag.toLowerCase(Locale.ROOT)) {    
// do something 
}

Copy link

github-actions bot commented Apr 30, 2025

Unit Tests Coverage Report

File Coverage Lines Branches
All files 76% 83% 70%
com.aws.greengrass.logmanager.services.DiskSpaceManagementService 71% 83% 60%
com.aws.greengrass.logmanager.CloudWatchLogsUploader 90% 97% 83%
com.aws.greengrass.logmanager.LogManagerService 68% 81% 55%
com.aws.greengrass.logmanager.LogManagerService$CurrentProcessingFileInformation 79% 89% 68%
com.aws.greengrass.logmanager.PositionTrackingBufferedReader 86% 87% 86%
com.aws.greengrass.logmanager.CloudWatchAttemptLogsProcessor 88% 89% 86%
com.aws.greengrass.logmanager.util.ConfigUtil 85% 85% 85%
com.aws.greengrass.logmanager.util.SdkClientWrapper 58% 67% 50%
com.aws.greengrass.logmanager.util.CloudWatchClientFactory 36% 36% 0%
com.aws.greengrass.logmanager.model.CloudWatchAttemptLogInformation 100% 100% 0%
com.aws.greengrass.logmanager.model.EventType 100% 100% 0%
com.aws.greengrass.logmanager.model.ProcessingFiles 65% 80% 50%
com.aws.greengrass.logmanager.model.ComponentType 100% 100% 0%
com.aws.greengrass.logmanager.model.LogFile 85% 78% 92%
com.aws.greengrass.logmanager.model.LogFileGroup 70% 75% 64%

Minimum allowed coverage is 65%

Generated by 🐒 cobertura-action against 759b80b

Copy link

github-actions bot commented Apr 30, 2025

Integration Tests Coverage Report

File Coverage Lines Branches
All files 68% 75% 61%
com.aws.greengrass.logmanager.services.DiskSpaceManagementService 47% 55% 40%
com.aws.greengrass.logmanager.CloudWatchLogsUploader 43% 45% 41%
com.aws.greengrass.logmanager.LogManagerService 82% 93% 71%
com.aws.greengrass.logmanager.LogManagerService$CurrentProcessingFileInformation 46% 55% 37%
com.aws.greengrass.logmanager.PositionTrackingBufferedReader 72% 82% 63%
com.aws.greengrass.logmanager.CloudWatchAttemptLogsProcessor 67% 73% 61%
com.aws.greengrass.logmanager.util.ConfigUtil 66% 61% 71%
com.aws.greengrass.logmanager.util.SdkClientWrapper 44% 47% 42%
com.aws.greengrass.logmanager.util.CloudWatchClientFactory 100% 100% 0%
com.aws.greengrass.logmanager.model.CloudWatchAttemptLogInformation 100% 100% 0%
com.aws.greengrass.logmanager.model.EventType 100% 100% 0%
com.aws.greengrass.logmanager.model.ProcessingFiles 81% 87% 75%
com.aws.greengrass.logmanager.model.ComponentType 100% 100% 0%
com.aws.greengrass.logmanager.model.LogFile 48% 50% 46%
com.aws.greengrass.logmanager.model.LogFileGroup 65% 74% 57%

Minimum allowed coverage is 58%

Generated by 🐒 cobertura-action against 759b80b

@junfuchen99 junfuchen99 merged commit 0c13acf into main May 2, 2025
6 checks passed
@junfuchen99 junfuchen99 deleted the fix branch May 2, 2025 20:45
robcmann pushed a commit that referenced this pull request Jun 25, 2025
(cherry picked from commit 0c13acf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants