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.
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.
Created attachment 29938 [details] Basically the same code you already see in the problem description
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.
>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.
> 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.
> 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.