alibaba / alibaba/testable-mock

使用@EnablePrivateAccess()注解,提示:java:找不到符号。

Open
#168 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
1.8k
Forks
306
PR merge metrics
No merged PRs in 30d

Description

我现在要测试类A的a()方法,这个方法是private的。
我首先使用@EnablePrivateAccess()注解,并写了2行代码:
Object o = A.a();
o = A.a();
在第二行o = A.a();的时候,会提示:java:找不到符号。

但是如果我改成
Object o = A.a();
Object o2 = A.a();
这样则不会报错。
或者
o = PrivateAccessor.invoke(xxx);
也不会报错。

我的疑问:使用@EnablePrivateAccess()之后去调用私有方法,不能赋值给已有的变量吗?必须声明一个新的变量去接收?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the minimal Java examples in the report: reuse an existing variable after @EnablePrivateAccess(), compare it with two newly declared variables, and compare PrivateAccessor.invoke(xxx). Trace the handling of @EnablePrivateAccess() and verify whether assignment to an existing variable should compile; done means the behavior is fixed or clearly documented with a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.