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 75236 - sources recompilation after constant member change
Summary: sources recompilation after constant member change
Status: RESOLVED INVALID
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: 5.x
Hardware: PC Linux
: P3 blocker (vote)
Assignee: issues@platform
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-19 14:03 UTC by lucrus
Modified: 2007-09-26 09:14 UTC (History)
2 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Basically the same code you already see in the problem description (10.00 KB, application/x-tar)
2006-04-19 14:11 UTC, lucrus
Details

Note You need to log in before you can comment on or make changes to this bug.
Description lucrus 2006-04-19 14:03:48 UTC
say we have:
public class A { public static final int N = 0; }

public class B
{  public static void main(String[] a) { System.out.println(A.N); }}

We run the code once and we get the correct output (0). Then we change only 
class A by making N be 1, e.g.

public class A { public static final int N = 1; }

and *we do not touch* the source file B.java. Now we run the program again, 
the ide recompiles A.java but the output is still 0. It seems that constants 
get copied into the .class files and the .class files don't get recompiled 
when the constants change.
Comment 1 lucrus 2006-04-19 14:11:37 UTC
Created attachment 29938 [details]
Basically the same code you already see in the problem description
Comment 2 Marian Mirilovic 2006-04-24 10:38:37 UTC
That's correct behaviour. All initialized static final fields that can be
evaluated at compile time must be compiled to bytecode that inlines the field
value. 

There won't be created dynamic link inside class B telling it to obtain the
value for N from class A at runtime, means value 0 is compiled into B.main()
directly. 

You have to clean both classes and compile them both once again.
Comment 3 lucrus 2006-04-24 22:52:14 UTC
>You have to clean both classes and compile them both once again
But I submitted the bug to the IDE component because, from my point of view, 
the IDE is sitting there just to help developers do this kind of things. I 
agree that the compiler can (must?) inline constants, but I'm saying that the 
IDE should recompile all the source files that need to be recompiled, because 
I think that the IDE should be something more than an Ant frontend.
Comment 4 Marian Mirilovic 2006-04-24 23:16:44 UTC
> But I submitted the bug to the IDE component because, from my point of view, 
> the IDE is sitting there just to help developers do this kind of things. I 

The ide component is used only like a distribution area ...

> agree that the compiler can (must?) inline constants, but I'm saying that the 
> IDE should recompile all the source files that need to be recompiled, because 
> I think that the IDE should be something more than an Ant frontend.

Nice wish, but I am not sure we can accomplish that: 
One could say: Why do you compile all files - files those haven't changed?
Somebody else could complain about performance of compilation. 

I don't think we can do that. This is job of ant/jdk not the IDE, the
compilation inside the IDE has to work the same way as outside the IDE. Anyway I
see your point, just don't think is the way we have to follow.
Comment 5 lucrus 2006-04-25 09:45:16 UTC
> One could say: Why do you compile all files
Obviously not ALL files, but only the ones that need recompilation. Seems to 
me it's quite a normal thing to recompile the files that depend on a file that 
has been modified. If we used C, the make command would do that just looking 
at dependencies and file modification times, it's not that hard to do. We 
already know that source file B.java depends on source file A.java because it 
references it (and the IDE already has the necessary code to computes this 
information in place, e.g. "Find usages"). Then we compare the last 
modification time of A.java and we see that it is more recent than the 
creation time of B.class, hence B.class needs to be rebuilt.

Maybe I should submit this feature request (but I still see it as a bug) to 
the Ant project, but I'm not sure if Ant already addressed this issue (maybe 
using an option the IDE is not aware of) or not.