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

Allow annotations on type use (List<@Safe String>) #699

Merged
merged 2 commits into from
Apr 11, 2022

Conversation

carterkozak
Copy link
Contributor

@carterkozak carterkozak commented Apr 8, 2022

==COMMIT_MSG==
Allow annotations on type use (List<@Safe String>)
==COMMIT_MSG==

See examples of enforcement in palantir/gradle-baseline#2187 Tests in particular: https://github.com/palantir/gradle-baseline/pull/2187/files#diff-9f39cf8d659f98e8e09abd4dff1235eb049a8b030370988a6c77d886d3f48bca

    @Test
    public void testUnsafeTypeParameterProvidesSafety() {
        helper().addSourceLines(
                        "Test.java",
                        "import com.palantir.logsafe.*;",
                        "import java.util.*;",
                        "class Test {",
                        "  void f(List<@Unsafe String> input) {",
                        "    // BUG: Diagnostic contains: Dangerous argument value: arg is 'UNSAFE' "
                                + "but the parameter requires 'SAFE'.",
                        "    fun(input.get(0));",
                        "  }",
                        "  private static void fun(@Safe Object obj) {}",
                        "}")
                .doTest();
    }

and

    @Test
    public void testUnsafeTypeParameterConsumesSafety() {
        helper().addSourceLines(
                        "Test.java",
                        "import com.palantir.logsafe.*;",
                        "import java.util.*;",
                        "class Test {",
                        "  void f(List<@Safe String> collection, @Unsafe String data) {",
                        "    // BUG: Diagnostic contains: Dangerous argument value: arg is 'UNSAFE' "
                                + "but the parameter requires 'SAFE'.",
                        "    collection.add(data);",
                        "  }",
                        "}")
                .doTest();
    }

@changelog-app
Copy link

changelog-app bot commented Apr 8, 2022

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Allow annotations on type use (List<@Safe String>)

Check the box to generate changelog(s)

  • Generate changelog entry

Copy link

@fawind fawind left a comment

Choose a reason for hiding this comment

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

Was wondering for a while what the difference between List<@Safe String> and @Safe List<String> is. But makes sense for the Map<@Safe String, @Unsafe String> example that you mention in the linked baseline PR!

@bulldozer-bot bulldozer-bot bot merged commit 377bf1f into develop Apr 11, 2022
@bulldozer-bot bulldozer-bot bot deleted the ckozak/type_use branch April 11, 2022 09:06
@svc-autorelease
Copy link
Collaborator

Released 1.26.0

@carterkozak
Copy link
Contributor Author

Was wondering for a while what the difference between List<@safe String> and @safe List is.

In the ideal case, we'd only annotate the generic type parameter for container types, however that may be confusing for devs, so I think it's reasonable to support both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants