Side effects in the inference engine?

The behaviour of the Idea's inference engine I am about to describe is not 100% reproducible and hence I am not posting it as a bug to the bug tracker but here -- hoping that someone would shed some light on the problem. If this is a bug then this is a very serious and disheartening bug.
The bahaviour persists in the last few recent releases of Pallada. I currently use build 2128. I also use javac 1.5 beta 2, with full support for generics, assertions and enums enabled in Idea.

The example code:
-


public interface IColor {...}

public enum RussianColor implements IColor{
White, Blue, Red;
.....
}

public class Test {
IColor r = RussianColor.Blue;
// <- flagged as error sometimes
...
}
-


Although I originally noticed such behaviour when attempting to insert the "colors" into some pairs, lists or maps but the above is the simplest posssible form when things apparently start going wrong. But no matter what I do the code always correctly compiles and runs. This is only the Idea's inference engine that troubles me, not the javac or java.

What is confusing is the fact that this will not always
be shown in red. It appears that there exist some side effects somewhere in the engine code, which depend on some initial conditions of this code or the status of some other, completely unrelated code from the same project
I work on.

For example, the moment I additionally define the 'CanadianColor' class using the old fashioned approach:
-


public class CanadianColor implements IColor {
private String name;

public static final Red = new CanadianColor ("Red");
public static final White = new CanadianColor("White");
private CanadianColor (String name) {
this.name = name;
}
}
-


and then insert the additional assignment to the
Test class:
-


public class Test {
IColor r = RussianColor.Blue;
IColor c = CanadianColor.Red;
...
}
-


the problem in first assignment dissapears. Sometimes!
But not always! Sometimes the problem will not appear at all to start with, but then it will appear again after many other compilations. So it is not 100% reproducible, but unfortunately persistent on the long run.

I have tried many things: rebuilding the code from scratch, restarting idea, or removing red flags from other unrelated code (This is yet another, generics-specific problem which I will describe in a separate post) that does not care for "colors" at all.
I wish I could be more specific, but short of sending you a copy of my entire project I cannot provide you with the exact "initial conditions" that would simulate my development environment.

Needless to say, this stuff is Idea-specific. I would have never noticed it in the Jedit for example, and I would have therefore happily continued the development -- without wasting my time on such issues. However, since our developers standarize on the Idea I cannot throw my code, flagged as red, into the common pool. No matter what kind of assurances I would be giving them about the code correctness their suspicion would still linger. :)

Regards,
Jan Skibinski,
Tucows Inc.,
Toronto, Ontario, Canada

2 comments
Comment actions Permalink

Yes, indeed I've seen this problem some time ago when following the same
pattern. However since it was not IDEA that I was thinking about when
writing that code, I silently forgot about this and now I cannot reproduce
it anymore. So, if you or anyone else can indeed shed some light on when
things go wrong, I would be happy to correct it.

WBR,
Eugene.

"Jan Skibinski" <no_mail@jetbrains.com> wrote in message
news:24325349.1087754259707.JavaMail.itn@is.intellij.net...

The behaviour of the Idea's inference engine I am about to describe is not

100% reproducible and hence I am not posting it as a bug to the bug tracker
but here -- hoping that someone would shed some light on the problem. If
this is a bug then this is a very serious and disheartening bug.

The bahaviour persists in the last few recent releases of Pallada. I

currently use build 2128. I also use javac 1.5 beta 2, with full support for
generics, assertions and enums enabled in Idea.
>

The example code:
----------------------------------------------------
public interface IColor {...}

>

public enum RussianColor implements IColor{
White, Blue, Red;
....
}

>

public class Test {
IColor r = RussianColor.Blue;
// <- flagged as error sometimes
..
}
----------------------------------
Although I originally noticed such behaviour when attempting to insert the

"colors" into some pairs, lists or maps but the above is the simplest
posssible form when things apparently start going wrong. But no matter what
I do the code always correctly compiles and runs. This is only the Idea's
inference engine that troubles me, not the javac or java.
>

What is confusing is the fact that this will not always
be shown in red. It appears that there exist some side effects somewhere

in the engine code, which depend on some initial conditions of this code or
the status of some other, completely unrelated code from the same project

I work on.

>

For example, the moment I additionally define the 'CanadianColor' class

using the old fashioned approach:

----------------------------------------------
public class CanadianColor implements IColor {
private String name;

>

public static final Red = new CanadianColor ("Red");
public static final White = new CanadianColor("White");
private CanadianColor (String name) {
this.name = name;
}
}
-----------------------------------------
and then insert the additional assignment to the
Test class:
------------------------------
public class Test {
IColor r = RussianColor.Blue;
IColor c = CanadianColor.Red;
..
}
-----------------------------
the problem in first assignment dissapears. Sometimes!
But not always! Sometimes the problem will not appear at all to start

with, but then it will appear again after many other compilations. So it is
not 100% reproducible, but unfortunately persistent on the long run.
>

I have tried many things: rebuilding the code from scratch, restarting

idea, or removing red flags from other unrelated code (This is yet another,
generics-specific problem which I will describe in a separate post) that
does not care for "colors" at all.

I wish I could be more specific, but short of sending you a copy of my

entire project I cannot provide you with the exact "initial conditions" that
would simulate my development environment.
>

Needless to say, this stuff is Idea-specific. I would have never noticed

it in the Jedit for example, and I would have therefore happily continued
the development -- without wasting my time on such issues. However, since
our developers standarize on the Idea I cannot throw my code, flagged as
red, into the common pool. No matter what kind of assurances I would be
giving them about the code correctness their suspicion would still linger.
:)
>

Regards,
Jan Skibinski,
Tucows Inc.,
Toronto, Ontario, Canada



0
Comment actions Permalink

Continuing about enum-related red flags that should not be there...
If you go back to enum defining module (RussianColor in my example) and do something stupid like replacing the keyword 'enum' with the keyword 'class' (which will cause more red flags) and then back with 'enum' the red flag that was visible in the calling class (Test in my example) will suddenly dissapear! But it will appear again after next restart of IDEA.

Jan

0

Please sign in to leave a comment.