Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2006

Tip: Looking for answers? Try searching our database.

Compiler mystery: Compiles classes that don't compile

Thread view: 
peeping_t@hotmail.com - 28 Feb 2006 22:09 GMT
Can someone please try and explain how this could even happen.

I'm about to start fixing some bugs in a program for a client. They
haven't really been that organised and just gave me some source code
from somewhere, which may or may not be the version of the source code
that was used to compile the version of the app that I am supposed to
fix bugs in.
Now to the problem. The code doesn't even compile. There's a file
Container.java, which is missing heaps of methods (private ones I guess
as they are only called from inside Container). I decompiled the actual
application and when I look at Container every single method that calls
one of the missing methods are decompiled to something similar like
this

   public void open()
   {
       throw new Error("Unresolved compilation problems:\n\tThe method
initMenu() is undefined for the type Container\n\tThe method handle()
is undefined for the type <anonymous subclass of
SelectionAdapter>\n\tThe method loadSettings() is undefined for the
type Container\n\tThe method init() is undefined for the type
Container\n\tThe constructor Blue(Container) is undefined\n");
   }

I don't understand how the compiler managed to compile this class and
replace the method body for the methods calling missing methods with
throw new Error("Unresolved...")

The thing is the application still works as Container is only
referenced as Container.class.getResourceAsStream(...)

The previous programmer was obviously doing some heavy refactoring to
get rid of the Container class, but managed to miss a couple of places
where the class was just referenced as Container.class

I still don't get how the compiler managed to produce a Container.class
file though

/Martin
Oliver Wong - 28 Feb 2006 22:17 GMT
> Can someone please try and explain how this could even happen.
>
[quoted text clipped - 33 lines]
> I still don't get how the compiler managed to produce a Container.class
> file though

   Eclipse lets you run classes with compile errors. I'm assuming it does
this by replacing the bodies of those methods with "throw new exception"
code, as you've described here.

   Perhaps your code was compiled by Eclipse or a similar compiler.

   - Oliver
peeping_t@hotmail.com - 01 Mar 2006 00:57 GMT
The previous programmer was most certainly using eclipse so thanks for
the explanation.
To me it seems to be a quite dangerous feature in eclipse.

/Martin
Oliver Wong - 16 Mar 2006 18:50 GMT
> The previous programmer was most certainly using eclipse so thanks for
> the explanation.
> To me it seems to be a quite dangerous feature in eclipse.

   It is sometimes convenient to run a program even though it contains some
compile errors. For example, a client is coming over, and you have to
perform a demo, but one of your coworkers was in the middle of modifying
some part of the application, and hasn't finished his changes. As long as
you don't actually cause the code with errors to execute, the application
appears to run just fine.

   - Oliver


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.