Skip to content
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

fix #2676: Safety propagation traverses complex record components #2700

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ private Description matchRecord(ClassTree classTree, ClassSymbol classSymbol, Vi
Safety safety = SafetyAnnotations.getTypeSafetyFromAncestors(classTree, state);
for (VarSymbol recordComponent : Records.getRecordComponents(classSymbol)) {
Safety symbolSafety = SafetyAnnotations.getSafety(recordComponent, state);
Safety typeSafety = SafetyAnnotations.getSafety(recordComponent.type, state);
Safety typeSymSafety = SafetyAnnotations.getSafety(recordComponent.type.tsym, state);
Safety recordComponentSafety = Safety.mergeAssumingUnknownIsSame(symbolSafety, typeSymSafety);
Safety recordComponentSafety = Safety.mergeAssumingUnknownIsSame(symbolSafety, typeSafety, typeSymSafety);
safety = safety.leastUpperBound(recordComponentSafety);
}
return handleSafety(classTree, classTree.getModifiers(), state, existingClassSafety, safety);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,7 @@ void testMethodDoesNotReturn() {

@Test
void testRecordWithUnsafeTypes() {
fix("--release", "17")
.addInputLines(
fix().addInputLines(
"Test.java",
"import com.palantir.tokens.auth.*;",
"import com.palantir.logsafe.*;",
Expand All @@ -290,6 +289,36 @@ void testRecordWithUnsafeTypes() {
.doTest();
}

@Test
void testWrappedRecordComponents() {
fix().addInputLines(
"Test.java",
"import com.palantir.logsafe.*;",
"import java.util.*;",
"class Test {",
" @Unsafe",
" class UnsafeType {}",
" record Rec1(UnsafeType val) {}",
" record Rec2(List<UnsafeType> val) {}",
" record Rec3(Optional<UnsafeType> val) {}",
"}")
.addOutputLines(
"Test.java",
"import com.palantir.logsafe.*;",
"import java.util.*;",
"class Test {",
" @Unsafe",
" class UnsafeType {}",
" @Unsafe",
" record Rec1(UnsafeType val) {}",
" @Unsafe",
" record Rec2(List<UnsafeType> val) {}",
" @Unsafe",
" record Rec3(Optional<UnsafeType> val) {}",
"}")
.doTest();
}

@Test
void testDoesNotAddSafeAnnotation() {
fix().addInputLines(
Expand Down
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-2700.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Safety propagation traverses complex record components
links:
- https://github.com/palantir/gradle-baseline/pull/2700