Wrong 'Unaccessed private field' message

I get a 'Unaccessed private field' with a number of code snippets, e.g. similar to this one:

---

private WorkflowRuntime workflowRuntime;

public ExpenseLocalService(WorkflowRuntime workflowRuntime)
{
this.workflowRuntime = workflowRuntime;
expenseReports = new List<![CDATA[]]>();
}

---
Why?

Thx,
Christian

4 comments
Comment actions Permalink

Hello Christian,

I believe ReSharper is right - if the code you posted is all code containing
the 'workflowRuntime' field.
The 'workflowRuntime' field is only assigned a value, but it is never used
for reading its value, so
ReSharper notices that and warns you.


Regards,
Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

I get a 'Unaccessed private field' with a number of code snippets,
e.g. similar to this one:

---

private WorkflowRuntime workflowRuntime;
public ExpenseLocalService(WorkflowRuntime workflowRuntime)
{
this.workflowRuntime = workflowRuntime;
expenseReports = new List<ExpenseReport>();
}

---
Why?
Thx,
Christian



0
Comment actions Permalink

Hello Dmitry,

I believe Christian is correct. this.workflowRuntime is global to the file.
indicates code preceeding and following this method.

The field is being initialized by the constructor. At this point it can be
accessed by other member methods and quite possibly it is accessed by a read-only
property

Hello Christian,

I believe ReSharper is right - if the code you posted is all code
containing
the 'workflowRuntime' field.
The 'workflowRuntime' field is only assigned a value, but it is never
used
for reading its value, so
ReSharper notices that and warns you.
Regards,
Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

>> I get a 'Unaccessed private field' with a number of code snippets,
>> e.g. similar to this one:
>>
>> ---
>>
>> private WorkflowRuntime workflowRuntime;
>> public ExpenseLocalService(WorkflowRuntime workflowRuntime)
>> {
>> this.workflowRuntime = workflowRuntime;
>> expenseReports = new List<![CDATA[(); >> } >>]]>
>> ---
>> Why?
>> Thx,
>> Christian


0
Comment actions Permalink

The key phrase here is that the variable "can be accessed" by other methods.
ReSharper is pointing out that the variable is being assigned a value, but
that value is not being read by the code. If you wrap the variable with an
externally visible property accessor to retrieve the value or retrieve the
value in code, the highlighting goes away. I prefer it to work this way
because it helps me locate those dead variables that are assigned values but
are never actually used.


"Matthew Moody" <moody.matt@gmail.com> wrote in message
news:987a136032408c8756a904275d4@news.jetbrains.com...

Hello Dmitry,

>

I believe Christian is correct. this.workflowRuntime is global to the
file.
indicates code preceeding and following this method.

>

The field is being initialized by the constructor. At this point it can be
accessed by other member methods and quite possibly it is accessed by a
read-only property

>
>> Hello Christian,
>>
>> I believe ReSharper is right - if the code you posted is all code
>> containing
>> the 'workflowRuntime' field.
>> The 'workflowRuntime' field is only assigned a value, but it is never
>> used
>> for reading its value, so
>> ReSharper notices that and warns you.
>> Regards,
>> Dmitry Shaporenkov
>> JetBrains, Inc
>> http://www.jetbrains.com
>> "Develop with pleasure!"
>>> I get a 'Unaccessed private field' with a number of code snippets,
>>> e.g. similar to this one:
>>>
>>> ---
>>>
>>> private WorkflowRuntime workflowRuntime;
>>> public ExpenseLocalService(WorkflowRuntime workflowRuntime)
>>> {
>>> this.workflowRuntime = workflowRuntime;
>>> expenseReports = new List<![CDATA[(); >>> } >>>]]>
>>> ---
>>> Why?
>>> Thx,
>>> Christian
>



0
Comment actions Permalink

Hello Lothan,

yes, exactly. ReSharper code analysis reflects the current state of code,
and the current code doesn't contain
any references that read the value of the 'workflowRuntime' field. So ReSharper
marks it as a definitely not accessed
(Matthew - it doesn't accessed by other members, because the only reference
to it is one in the constructor).
Once you've created a get accessor, you effectively create a 'read reference',
so the warning goes away.

Regards,
Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

The key phrase here is that the variable "can be accessed" by other
methods. ReSharper is pointing out that the variable is being assigned
a value, but that value is not being read by the code. If you wrap the
variable with an externally visible property accessor to retrieve the
value or retrieve the value in code, the highlighting goes away. I
prefer it to work this way because it helps me locate those dead
variables that are assigned values but are never actually used.

"Matthew Moody" <moody.matt@gmail.com> wrote in message
news:987a136032408c8756a904275d4@news.jetbrains.com...

>> Hello Dmitry,
>>
>> I believe Christian is correct. this.workflowRuntime is global to the
>> file.
>> indicates code preceeding and following this method.
>> The field is being initialized by the constructor. At this point it
>> can be accessed by other member methods and quite possibly it is
>> accessed by a read-only property
>>
>>> Hello Christian,
>>>
>>> I believe ReSharper is right - if the code you posted is all code
>>> containing
>>> the 'workflowRuntime' field.
>>> The 'workflowRuntime' field is only assigned a value, but it is
>>> never
>>> used
>>> for reading its value, so
>>> ReSharper notices that and warns you.
>>> Regards,
>>> Dmitry Shaporenkov
>>> JetBrains, Inc
>>> http://www.jetbrains.com
>>> "Develop with pleasure!"
>>>> I get a 'Unaccessed private field' with a number of code snippets,
>>>> e.g. similar to this one:
>>>>
>>>> ---
>>>>
>>>> private WorkflowRuntime workflowRuntime;
>>>> public ExpenseLocalService(WorkflowRuntime workflowRuntime)
>>>> {
>>>> this.workflowRuntime = workflowRuntime;
>>>> expenseReports = new List<![CDATA[(); >>>> } >>>>]]>
>>>> ---
>>>> Why?
>>>> Thx,
>>>> Christian


0

Please sign in to leave a comment.