This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes possible java bug Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "possible java bug" Watch "possible java bug" New topic
Author

possible java bug

Francisco A Guimaraes
Ranch Hand

Joined: Mar 20, 2002
Posts: 182
i was doing some constructor exercises and did this piece of code:
public class Test {
public static void main(String args[]) {
Test t = new Test();
}
public Test() {
this(5);
System.out.println("Test()");
}
public Test(int i) {
this();
System.out.println("Test(int)");
}
}
jikes complain about it saiyng "The constructor "Test" may not directly or indirectly invoke itself". But javac 1.3 and 1.4 compiles without error. Is this a bug from javac ? Or is it supposed to overlook this?
Thanks,
Francisco


Francisco<br />SCJP<br />please use the [code][/code] tags when showing code.Click <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page" target="_blank" rel="nofollow">here</a> to see an example.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
The JLS doesn't actually say this is illegal, so in one sense it's a "bug" in jikes to forbid this. However it's obvious that this code can never actually execute, so jikes is doing you a favor by complaining at compile time. SDK 1.3 and 1.4 will wait until run time to fail, with this code.


"I'm not back." - Bill Harding, Twister
Francisco A Guimaraes
Ranch Hand

Joined: Mar 20, 2002
Posts: 182
that�s exactly what happens, when I try to run it, I get a "StackOverflowError". Should I write an email to Sun? or do you think they are aware of this?
I looked on java�s bug parade and found nothing on this.what�s your sugestion?
[]�s
Francisco
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Francisco and Jim:
From the JLS section 8.8.5:
It is a compile-time error for a constructor to directly or indirectly invoke itself through a series of one or more explicit constructor invocations involving this.
So it might be a bug in the compiler. Although I want to think I've read something about it here once before, you might want to do a search for it.


Dave
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Good catch, Dave. I was actually surprised when I couldn't find a place in the JLS forbidding it - I was looking in 8.8.5.1. Should have looked up the page a tiny bit. So yes, it is a bug in Sun's SDK's. This fits the general pattern though, which is that jikes is better about following the JLS than Sun is. I'd file a bug report, sure, but I doubt Sun's going to be in any rush to fix this one. Practically speaking, it doesn't really matter most of the time - anyone trying to do something like this will find out soon enough that it can't be done. It will probably be viewed as fairly minor, from Sun's perspective.
Francisco A Guimaraes
Ranch Hand

Joined: Mar 20, 2002
Posts: 182
Thanks for the help you both...I think i�ll search the saloon like you said Dave, and if I don�t find anything, I�ll post the bug on Sun�s site.
Thanks again,
Francisco
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: possible java bug
 
Similar Threads
default package access
super class where?
Practice Question
default package access
Help with compiling packages