I am creating a Liferay portlet in Liferay Developer Studio (which is Eclipse) and found a very, very strange behavior.
In one JSP, every time some specific variable is set, its variable has its value changed to null in the next line. This is so strange that I felt that I should make a screencast of it – and it is in this YouTube video.
The class AnoterFieldComparator extends OrderByComparator from Liferay, as seen below. This problem just happened to OrderByComparator subclasses as well, although this makes no sense to me.
public class AnoterFieldComparator extends OrderByComparator {
@Override
public int compare(Object o1, Object o2) {
Example example1 = (Example)o1;
Example example2 = (Example)o2;
return Integer.parseInt(""+(example1.getAnotherField() - example2.getAnotherField()));
}
}
(Yes, there is a typo. It was just an experiment 🙂 )
The project can be seen here and here. I know the question is not that well written, but I am pretty amazed, usually only novices talk about this kind of behavior, and they are wrong most of the time.
What is the toString method of AnoterFieldComparator ( or its super class )?
The value column in you screen cast does not go to null just the box down below which is the string representation of this class, at the end of the video you can still see to the right of comparitor the class and the object id, so the variable is not null just the to string method either returned null (0x0) or the string “null”.