Skip to Content.
Sympa Menu

mace-opensaml-users - RE: bug in constructing objects using InputStream

Subject: OpenSAML user discussion

List archive

RE: bug in constructing objects using InputStream


Chronological Thread 
  • From: Bryan Field-Elliot <>
  • To: Nick Laqua <>
  • Cc: Scott Cantor <>,
  • Subject: RE: bug in constructing objects using InputStream
  • Date: 14 Mar 2003 13:55:21 -0700

Actually if I may interject a slight correction here.....

True in C++, the superclass constructor is always called before the subclass constructor.

In Java however, you can explicitly call the superclass constructor at any point in your subclass constructor, by calling super(), or super(param1, param2, ...) to invoke a different superclass constructor.

Place this call (super()) as the first statement in your subclass constructors, and the behavior will be (mostly) equivalent to C++'s behavior. Note that (obviously), the special method "super()" can only be invoked from a class constructor, and not from any other method.

Bryan


On Fri, 2003-03-14 at 09:18, Nick Laqua wrote:
Yes, that's correct, the derived object isn't constructed yet at that level ;-(((...also applies to other classes like SAMLAssertion (Collection statements).

the solution might be even more complex, as the super constructor always has to be always the first call within the original constructor, so it might be impossible to initialize before that as the damage is done within the super constructor (but I am not totally sure)

Nick



-----Original Message-----
From: Scott Cantor [mailto:]
Sent: Friday, March 14, 2003 5:10 PM
To: Nick Laqua;
Subject: RE: bug in constructing objects using InputStream


> When constructing a SAMLRequest using an InputStream, the
> super class SAMLObject calls the "virtual" polymorphic method
> fromDOM without the private members being initialized (e.g.
> respondWiths).

IOW, despite the fact that in Java when you call a virtual function from a constructor, it calls the derived version, it still
hasn't constructed the object at that level yet?

Ugh.

In C++, the behavior is explicit that you don't expect the overridden version to get called from the base, since the subclass isn't
constructed yet, but since Java calls the subclass version of the method, I assumed it did the right thing to make that viable.

I presume the fix is to initialize explicitly in the constructor(s).

-- Scott





Archive powered by MHonArc 2.6.16.

Top of Page