Solved

Odd Java <init> problem..

Posted on 2004-08-15
5
718 Views
Last Modified: 2013-11-23
I have a simple program (code below), which gives a series of odd results.

The specifics are:
1) odd error; I get an error From Eclipse when running it; (compiles fine)
   java.lang.VerifyError: Expecting a stackmap frame at branch target 44 in method Test.Composite.<init>([LTest/Component;)V
      at Test.Computer_Vis.main(Computer_Vis.java:21)
Exception in thread "main"
  This means something wrong in the constructors (<init> is a compiler built constructor method.)

Bit if I remove the loop code (marked "code-2" below), it compiles fine, but doesn't do anythign when run. The removed code is not even at the site of the reported error!
  [It may be that Eclipse is confused, it is not totally Java 1.5 ready yet, this is a Beta]

2) So, compile it under Tiger (Java 1.5) directly,
Seems to compile, but the prints in the constructors never print...? Prints in Main do, but constructors don't seem to be called.

Perhaps this is an Eclipse (Beta) bug, but if so, what is the real error? Seeral odd things here!

Thanks
------------------------------------
Code In question:

/*
 * Created on Aug 13, 2004
 *
 *
 */
package Test;

/**
 * @author guthrie
 *
 */
import java.util.*;

public class Computer_Vis {
      public static void main(String argv[]) {
 
      // Build a sample system ...
      Component computer1 =
            new Cabinet(  );
      Component computer2 =
                  new Cabinet( new Video() );
      }
}

// Base of Equipment class
abstract class Component {  }

// ----- Leaf nodes; concrete components...
class Video extends Component { }

// ------ Now the composite sub-type(s)
abstract class Composite extends Component {
   // Code-1
   List<Component> parts = new ArrayList<Component>();
   
   Composite(  ) { }
   Composite( Component  c ) { parts.add(c);}
   Composite(Component[] Cs) {
      System.out.println("Hello");
      /* for (Component c : Cs)
       *             parts.add(c);
       */
      /*  Code-2
      for (int i=0; i<Cs.length; i++ ) {
            parts.add(Cs[i]);
            }
       */
      System.out.println("Length:" + Cs.length);
      }
}

class Cabinet extends Composite {
      Cabinet()                { super(); }
  Cabinet( Component  c ) { super(c);}
  Cabinet(Component[] Cs) {      super(Cs); }
  }

   
0
Comment
Question by:guthrie
  • 3
5 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 11807438
It is a bug in Eclipse, have you tried upgrading your Eclipse installation: https://bugs.eclipse.org/bugs/show_bug.cgi?id=63591
0
 
LVL 35

Accepted Solution

by:
girionis earned 250 total points
ID: 11807446
Well as the comments indicate it is a bug with the 1.5.0-beta-b31 (javaloibby alpha version of jdk1.5). From the link above:

"I think, I found the problem.  It's a bug related to 1.5.0-beta1-b31 (javalobby
alpha version).  I tried another computer where I've 1.5.0-beta1-b32c (official
beta1 I think) installed.  Now it works.  Time to upgrade my version...

You can close the bug.  Thanks for your patience :)"
0
 
LVL 22

Expert Comment

by:NovaDenizen
ID: 11810508
Maybe you should search and replace "Component" with "Test.Component".  java.awt.Component may be treated as some kind of special or optimized case in your java compilers.  I know you're not importing anything from java.awt, but it's possible the compiler's not doing the right thing.
0
 

Author Comment

by:guthrie
ID: 11812627
Yes, thanks.

I was using beta b-31.

If I download J2SE v 5.0 Beta 2, I assume this is then the latest-and-greatest, ala B32c?
Their naming is confusing; I had J2sdk-1.5, now options are
JRE1.5, and JDK1.5.

I wish that Eclipse updates would automatically pick-up various required updates as detected. I take it I don't need to upgarde Eclipse, but just the Tiger SDK.

Thanks will try it. Good job!

(PS: "Component" seems not to be a problem.)
0
 
LVL 35

Expert Comment

by:girionis
ID: 11817884
Thank you for accepting, glad I was of help :)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count11 challenge 6 47
Eclipse Neon and jdk 1.8.0 11 67
groovy example issue 10 66
create a gui in perl 3 45
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now