aws-powertools / powertools-lambda-java

Powertools is a developer toolkit to implement Serverless best practices and increase developer velocity.
https://docs.powertools.aws.dev/lambda/java/
MIT No Attribution
277 stars 83 forks source link

Remove usage of `setAccessible` #1449

Open scottgerring opened 9 months ago

scottgerring commented 9 months ago

We use java.lang.reflect.AcessibleObject#setAccessible to reflectively access fields in both the matrics and SQS utilities. We should try and remove this, if we can.

What were you trying to accomplish?

Expected Behavior

No need to reflectively access private object information in the libraries themselves. In tests this is fine.

Current Behavior

Examples:

https://github.com/aws-powertools/powertools-lambda-java/blob/4d3484fdea1a519f06569ef688efd2bf32a689b8/powertools-metrics/src/main/java/software/amazon/cloudwatchlogs/emf/model/MetricsLoggerHelper.java#L36

https://github.com/aws-powertools/powertools-lambda-java/blob/4d3484fdea1a519f06569ef688efd2bf32a689b8/powertools-sqs/src/main/java/software/amazon/lambda/powertools/sqs/SqsUtils.java#L619

https://github.com/aws-powertools/powertools-lambda-java/blob/4d3484fdea1a519f06569ef688efd2bf32a689b8/powertools-metrics/src/main/java/software/amazon/lambda/powertools/metrics/internal/LambdaMetricsAspect.java#L56

Possible Solution

We can either 1/ find a way to avoid the need or 2/ say "this is too hard, we will remove it in V2 by changing the interface". However we should be confident that there is no way forward with the existing interface.

Steps to Reproduce (for bugs)

Environment

scottgerring commented 9 months ago

For the metrics one, what are we doing in the v2 rewrite #1405 ? We certainly shouldn't introduce this again.

scottgerring commented 9 months ago

For the SQS one, we might be able to ignore it; we have deprecated it and introduced the new SQS libraries #1317