Strange error: Cannot use NEW statement with class 'xxx&

Posted by toomaskask on 14-Nov-2014 11:07

Hi!

Very strange problem (and probably easy to solve):

class A: one public constructor.

--> { super (). ... }

class B: inherits from class A, one public constructor

--> { super (). ... }

.p module tries to create new object and gets error "Cannot use NEW statement with class 'xxx'  using a protected constructor. (12959)".

I don't have any protected constructors in my code.

Ideas?

All Replies

Posted by TheMadDBA on 14-Nov-2014 11:11

What version of OE are you running and were both classes compiled using that version?

knowledgebase.progress.com/.../P132976

Posted by toomaskask on 14-Nov-2014 11:16

Eh, sorry.

OE 11.3.2 @ Linux

Code is fresh and compiled.

Wbr,

Toomas

Posted by Shelley Chase on 14-Nov-2014 11:21

You are calling super with no parameters. Do you have a public constructor with no parameters for Class A?

Posted by Peter Judge on 14-Nov-2014 11:23

Can you post the (real) ABL code? not just the pseudo-code?

-- peter

Posted by Thomas Mercer-Hursh on 14-Nov-2014 11:43

Why is there a super() in Class A if it doesn't inherit from anything?

Posted by toomaskask on 14-Nov-2014 12:02

schas: yes, I have public constructor with no parameters in Class A .

Thomas: because PDS generates such a code?

Peter: full code is too big to post it here. But you can trust me, there is no protected constructor. :-)

I have strange feeling that this problem is somehow related to how our code is compiled & cached in client side.

Because same code worked yesterday, but started to fail occasionally today ie sometimes it worked, sometimes not.

I'll investigate this theory further.

Wbr,

Toomas

Posted by Peter Judge on 14-Nov-2014 12:11

Assuming nothing changed between then and now ...
 
Make sure you (manually) delete all r-code first – there are times when the compiler (or PDSOE) puts rcode where you don't expect/want it.
 
I was more after the 'super' or 'this-object' calls and the constructor signatures.
 
-- peter
 
[collapse]
From: toomaskask [mailto:bounce-toomaskask@community.progress.com]
Sent: Friday, 14 November, 2014 13:03
To: TU.OE.Development@community.progress.com
Subject: RE: [Technical Users - OE Development] Strange error: Cannot use NEW statement with class 'xxx' using a protected constructor. (12959)
 
Reply by toomaskask

schas: yes, I have public constructor with no parameters in Class A .

Thomas: because PDS generates such a code?

Peter: full code is too big to post it here. But you can trust me, there is no protected constructor. :-)

I have strange feeling that this problem is somehow related to how our code is compiled & cached in client side.

Because same code worked yesterday, but started to fail occasionally today ie sometimes it worked, sometimes not.

I'll investigate this theory further.

Wbr,

Toomas

Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

Posted by Thomas Mercer-Hursh on 14-Nov-2014 12:33

So, Peter, why *does* PDSOE generate that super()?

Posted by Peter Judge on 14-Nov-2014 12:40

ClassA inherits from Progress.Lang.Object, which has a default constructor (ie no parameters).
 
The explicit SUPER() call is not necessary; I suspect it's there as a nicety (but cannot tell you for sure).
 
-- peter
 
 
 
 
 
[collapse]
From: Thomas Mercer-Hursh [mailto:bounce-tamhas@community.progress.com]
Sent: Friday, 14 November, 2014 13:34
To: TU.OE.Development@community.progress.com
Subject: RE: [Technical Users - OE Development] Strange error: Cannot use NEW statement with class 'xxx' using a protected constructor. (12959)
 
Reply by Thomas Mercer-Hursh

So, Peter, why *does* PDSOE generate that super()?

Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

Posted by Thomas Mercer-Hursh on 14-Nov-2014 12:53

Understood.  Let me ask this.  

Is there any difference in the sequence of operations if it is there or not?

Does it make any sense or have any impact to have that top level super somewhere other than the first statement?

Posted by Peter Judge on 14-Nov-2014 13:11

> Does it make any sense or have any impact to have that top level super somewhere other than the first statement?

Compiler won't allow a SUPER() or THIS-OBJECT() call to be anywhere but the first line of a constructor.  This is because the object tree is built top-down since children can reference public and protected members in their constructors.
 
If the first (statement, as opposed to DEF VARs) line is NOT SUPER() or THIS-OBJECT() then the AVM calls SUPER() – the default constructor. This is true of a first-generation child too.  PLO has only the single default constructor which results in that constructor always being run, either via an explicit SUPER() call or by default.
 
-- peter
 
[collapse]
From: Thomas Mercer-Hursh [mailto:bounce-tamhas@community.progress.com]
Sent: Friday, 14 November, 2014 13:54
To: TU.OE.Development@community.progress.com
Subject: RE: [Technical Users - OE Development] Strange error: Cannot use NEW statement with class 'xxx' using a protected constructor. (12959)
 
Reply by Thomas Mercer-Hursh

Understood.  Let me ask this.  

Is there any difference in the sequence of operations if it is there or not?

Does it make any sense or have any impact to have that top level super somewhere other than the first statement?

Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

Posted by Thomas Mercer-Hursh on 14-Nov-2014 14:32

I.e., it makes no difference whether there or not, exactly the same thing is going to happen.  I can see why it should be there in the subclass because it makes the relationship explicit, not to mention that one often wants to pass through a parameter.  I understand that technically the same is true with Pro.Lang.Object, but it seems less valuable there.

This thread is closed