This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 258106 - Static non-final field runtime value different from declaration value.
Summary: Static non-final field runtime value different from declaration value.
Status: NEW
Alias: None
Product: debugger
Classification: Unclassified
Component: Java (show other bugs)
Version: 8.1
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Martin Entlicher
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-23 07:18 UTC by ajh
Modified: 2016-03-24 15:59 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ajh 2016-02-23 07:18:40 UTC
I've declared a static non-final float variable in a class.  It is non-final because I need to modify it at runtime to track statistics.  

eg:

public class Stats{
     public static float StatisticsValue = 0.9f;
}

I then place a breakpoint in a different class in the same project on a line of code that reads from this static variable to a local variable.  


float localValue=Stats.StatisticsValue;


After hitting that breakpoint, when I hover the mouse over the 'Stats.StatisticsValue' variable (or look at the watch) I get the error message as reported in bug 118785.  However keep reading, this is not my issue.

When I then step to the next line, the watch shows localValue is set to 0.9f, as expected. However the watch for Stats.StatisticsValue now shows '0.87f'.  Why? What on earth is going on here?

As an additional check I have a println(Stats.StatisticsValue) in the main loop of the application.  When I allow the application to resume running, this println statement actually displays 0.87f. There are a few if statements that I can confirm are being given the wrong value of 0.87f.

This is greatly concerning, at runtime my application is using a static value that is different from the value specified in code.

Before anyone asks as a sanity check I performed a project wide file search (*.java) for the value '.87'.  No place in the entire code-base sets this value.

It is possible that 0.87f is a value I had written in the assignment to Stats.StatisticsValue during a previous development session. 

So I thought perhaps it was still hard-coded in class file?  So to be sure I did a 'Clean and build' for the project in question.  No change, the same bizarre value of 0.87f is returned.

I thought initially it was all related to bug 118785 and it was just the debugger displaying a possibly cached old value.  However this seems more serious as it is actually changing the behavior of my application.


More information:

Using Gradle 2.9 and the Gradle daemon for builds.
Additional libraries: Libgdx 1.7.1
Comment 1 ajh 2016-02-23 07:32:17 UTC
More info:

I created a basic Java Application (no Gradle, libgdx etc), with just the main class and another test class with a public static float (non-final).  The problem does not occur, the static variable always correctly remains the value it is declared as.

As another test, I closed the IDE, killed the Gradle daemon process and ensured no other java processes were running (for all users).  Started the IDE again, ran 'Build and Clean'.  Ran the project under the debugger and received the same incorrect value of 0.87f at runtime even though it is declared in code as 0.9f