Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

neverHappen variable in compiled classes

Tags:

grails

groovy

I changed a couple of classes in my Grails project and built a war file. I then compared the .class files from the new war to the ones in the war which was built before my changes (on a different machine, if that matters) and it turns out that many (if not all) .class files are different. Looking at the decompiled classes it seems that the differences are because of a timestamp in a variable such as this:

public static long __timeStamp__239_neverHappen1360886953029;

Does anyone know what this variable is?

like image 652
zoran119 Avatar asked Mar 09 '13 11:03

zoran119


People also ask

Can you declare variables in a class?

Typically, you declare a class's variables before you declare its methods, although this is not required. Note: To declare variables that are a member of a class, the declarations must be within the class body, but not within the body of a method. Variables declared within the body of a method are local to that method.

Why is a static variable also referred to as a class variable?

Static variables should be used to track data that are shared in common by all of the instances of a class. These variables are also called class variables. Class variables are distinguished from instance variables. Instance variables track the data that belong to each individual object of a class.

What is compile time variable?

A Java variable is a compile-time constant if it's of a primitive type or String, declared final, initialized within its declaration, and with a constant expression. Strings are a special case on top of the primitive types because they are immutable and live in a String pool.

How do you declare a class variable in a classroom?

Class variables also known as static variables are declared with the static keyword in a class, but outside a method, constructor or a block. There would only be one copy of each class variable per class, regardless of how many objects are created from it.


2 Answers

It comes from groovy class generation.

See some discussion here http://groovy.329449.n5.nabble.com/Timestamp-in-class-files-leads-to-huge-patches-td365696.html

For the sake of completeness , quoted here:-

For Groovy's own recompilation mechanism. Sources are not always in file form, so we can't "just" check the file timestamp, so we had to store that timestamp somewhere... and where better than in the class itself since that's all we have?

On Tue, Mar 3, 2009 at 10:39, Jason Dillon <[hidden email]> wrote:

Why does groovyc capture the compile timestamp? What good is that for?

like image 131
Jayan Avatar answered Nov 02 '22 22:11

Jayan


This changed in Groovy 2.4, the .class files no longer contain a timestamp field.

https://github.com/groovy/groovy-core/commit/bcdb89e

like image 1
Emmanuel Bourg Avatar answered Nov 02 '22 23:11

Emmanuel Bourg