question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

let @VisibleForTesting tells original visibility of annotated element

See original GitHub issue

Original issue created by skypencil on 2014-01-22 at 02:13 AM


Hello, I am trying to implement static code analysis tool which detects illegal method call like below:

  // an implementation which has a method annotated by @VisibleForTesting   class MyImplementation {     @VisibleForTesting     /* private */ void method() { … }   }

  // another implementation   class AnotherImplementation {     void method() {       new MyImplementation().method(); // illegal method call, because this class is not test code     }   }

To find illegal method calling, we should know the original visibility of annotated element (method in this case). In some case it is difficult to guess original visibility, so I want to enhance @VisibleForTesting to explain it like below:

@VisibleForTesting(original = Visibility.PRIVATE)
void method() { ... }

I think all static analysis tool which uses this annotation needs method to judge illegality of method call, so I have added methods into Visibility enum in attached diff. It is also good to make this enum simple like com.android.internal.annotations.VisibleForTesting annotation. See https://github.com/android/platform_frameworks_base/blob/8b2c3a14603d163d7564e6f60286995079687690/core/java/com/android/internal/annotations/VisibleForTesting.java

Issue Analytics

  • State:open
  • Created 9 years ago
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
kluevercommented, Sep 20, 2017

@eaftan Any chance we could get error-prone to support (check) the visibility field?

1reaction
zhangmingleicommented, Nov 3, 2017

@jbduncan Thank you for your reply. I agree with you about this issue. I put the code here just as a reference, that means, we can use reflections implements that ,but It has it’s limitations.

Read more comments on GitHub >

github_iconTop Results From Across the Web

VisibleForTesting - Android Developers
Denotes that the class, method or field has its visibility relaxed, so that it is more widely visible than otherwise necessary to make...
Read more >
`@VisibleForTesting` still treated as `@TestOnly` even if used ...
It says. This inspection reports usages of @TestOnly - or VisibleForTesting annotated methods and classes in production code. The problems are not reported ......
Read more >
Behavior of @VisibleForTesting annotation on scala
I'm testing a method I added to a scala class whose constructor is marked as private. It is accessed via a singleton Object,...
Read more >
Some things to consider before using the @VisibleForTesting ...
As the documentation describes the @VisibleForTesting annotation allows you to change a functions visibility modifier to be more relaxed so ...
Read more >
[Java] Class members annotated with @VisibleForTesting ...
... Android and AssertJ include an annotation @VisibleForTesting that can be used to mark methods and fields whose visibility restrictions ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found