added @SafeVarargs to ensure warnings error enabled on main#20945
added @SafeVarargs to ensure warnings error enabled on main#20945ThyTran1402 wants to merge 1 commit intoopensearch-project:mainfrom
Conversation
Signed-off-by: Thy Tran <58045538+ThyTran1402@users.noreply.github.com>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|
❌ Gradle check result for 98f884e: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
Description
Replace
@SuppressWarnings("unchecked")with@SafeVarargson all generic varargs methods across libs/core and libs/common.Root cause: Methods with generic varargs parameters (e.g., Iterator<? extends T>..., E...) produce two distinct compiler warnings:
A declaration-site warning (-Xlint:varargs): "Possible heap pollution from parameterized vararg type"
A call-site warning (-Xlint:unchecked): "unchecked generic array creation for varargs parameter"
With -Werror enabled globally, any call site outside that scope remained exposed and could fail compilation on a cold build which is exactly what caused the Maven snapshot publication to break after #9120 was merged as mentioned in #9149.
Fix: Annotate each safe generic varargs method with
@SafeVarargsat the declaration. This suppresses both warnings for all callers automatically and is semantically correct because none of these methods write typed elements back into their varargs arrays with no heap pollution.Related Issues
Resolves #9150
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.