• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

JBuilder successfully compiling a class file that inadvertantly referenced a "count" variable that I never declared anywhere.

I'm not a Java whiz kid, but I certainly know enough to have gotten by quite successfully over these past 7 years.  Servlets primarily.  And I still use my 'ole JBuilder 3 environment.   Ok, them's my credentials, so I hope you don't roll your eyes when you read what I'm experiencing...

Inadvertantly, I saw my Jbuilder3 was compiling (successfully, with no errors or warnings) a servlet that contained a reference to a "count" variable that I NEVER declared anywhere. It took me some time to whittle down the mysterious code to the following three files: BlahBlah.java, Dummy1.java, and Dummy.java.

I have yet to understand WHY this is happening.  In the Project properties, I am using JDK 1.2 (yes, I know, maybe a bit outdated but it's worked fine for my simple needs all these years).  I have cleared any reference to external Java libraries.  So the code in question is the 3 simple java files below.  Note there are no "import" statements anywhere.  And each time I compile, I've erased all ".class" files from previous compiles, just to be sure "count" is not referenced in some location I'm not aware of (but that wouldn't make sense anyway, because shouldn't "count" be dot-prefixed with the classname it's declared in?  And no, I'm not inheriting from anything (as you can see below).

The odd thing is this...   If I change anything, such as remove one of the files from my package (appropriately named "wierd"), the compiler then picks up on the undeclared "count" line in Dummy.java.

One of these days, I'll have to wean myself off JBuilder3 and get into using a copy of JBuilder2005 I have.  But in the mean time, I am perplexed by this!  Simple changes like removing the call to "Dummy1.sillyUselessProcThatReturnsNull();" in the Dummy unit will cause the compiler to finally see that "count" is not known.

90% of the time, I always seem to find the problem myself after posting my question online, so maybe that will happen here!  But in the mean time, if anyone can explain why this is happening....   well, I'd appreciate it.

SB

========= BlahBlah.java ===========
package wierd;

class BlahBlah  {

  public BlahBlah() {
    Dummy1.sillyUselessProcThatReturnsNull();
  }

}

========= Dummy.java ============
package wierd;

class Dummy  {

  public Dummy() {
    count = 0;   // WHERE IS THIS DECLARED????????????
    Dummy1.sillyUselessProcThatReturnsNull();
  }

}

========= Dummy1.java ==========
package wierd;

class Dummy1 {

  public static void sillyUselessProcThatReturnsNull() {
   "HELLO".equalsIgnoreCase( "GOODBYE" );
  }
}


0
stockblocks
Asked:
stockblocks
  • 3
  • 2
1 Solution
 
objectsCommented:
shouldn't compile, maybe a bug in JB.
have you tries compiling from command line with javac?
0
 
stockblocksAuthor Commented:
Never used javac, but tried your suggestion.  In MS-DOS panel, I went into the folder containing the 3 java files and issued this command:

C:\JBuilder3\myprojects\wierd\javac  Dummy.java

Sure enough, it picked up on the line showing "count = 0"  (error msg was "cannot resolve symbol").

It also couldn't resolve the reference to Dummy1 in the next line, since javac doesn't know about other files in the "package".  So on a side note, how would I compile the entire package with javac?  Sorry if this is a silly question.  Does it entail use of a "make-like" file?  I've seen how JBuilder 3 creates a 'dependency' file... is that what javac uses to compile all servlets contained in a package?

SB
0
 
objectsCommented:
you need to add your projects directory to your classpath, eg.

javac -classpath C:\JBuilder3\myprojects Dummy.java

some good background on classpaths:
http://mindprod.com/jgloss/classpath.html
0
 
stockblocksAuthor Commented:
Got it.  Thanks.   So now the only error is the unresolved symbol reference to "count", as is expected!

But I'm really disappointed that JBuilder3 didn't find it.  Might assigning a different JDK fix it?  I.e., could this be due to a problem with the JDK I'm using?  Doubtful perhaps...  but I've gone so many years really thinking that JBuilder was "perfect", so I'd hate think it's a compiler bug.

Oh well.  You were extremely fast in assisting me.  I'll accept that as the definitive answer.

Thanks,

SB
0
 
objectsCommented:
doubt its a problem with the jdk, more likely a problem with JB itself
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now