Home » Developer & Programmer » JDeveloper, Java & XML » Java Stored Procedure - if expression (Oracle 10)
Java Stored Procedure - if expression [message #544100] Mon, 20 February 2012 03:34 Go to next message
van_culo
Messages: 6
Registered: February 2012
Location: Milano, Italy
Junior Member
Hi I have written a first stored procedure for my company and immediately we have run in to a problem that seems to be a bug Oracle, but maybe someone could share some light on this if it is not a bug.

At a certain point in a class Java we have a code simple as this:

Integer one = null;
Integer two = null;

if(one!=null&&two.intValue()>0) then....

This extremely simple example throws a NullPointerException in Oracle. But this goes against the Java Language Specification! According to this specification:

"The && operator is like & (ยง15.22.2), but evaluates its right-hand operand only if
the value of its left-hand operand is true."

That is if "one!=null" is true the right hand operand "two.intValue()" should be evaluated, but clearly for us it is ALWAYS being evaluated. Can someone please explain? Discovering this in our first function, makes us worry, a lot, if there are other surprises to expect? Before deploying the class we tested it with JUnit, and we are of course using JDK1.4, the same as on Oracle server.

We are using Oracle 10 with JDK1.4.2_04.

Any help, documentation or information is extremely welcome.

Tim Mickelson
Re: Java Stored Procedure - if expression [message #544105 is a reply to message #544100] Mon, 20 February 2012 03:48 Go to previous messageGo to next message
Michel Cadot
Messages: 68624
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
Can someone please explain?


What do you want us to explain? It seems you understand how it works, now there is nothing to explain it works as it works (bug or not).

If you think it is a bug then raise a SR to Oracle.
However you have a straight workaround: split it in 2 "if".

You can also upgrade to a new version of Oracle (and JDK).

Regards
Michel
Re: Java Stored Procedure - if expression [message #544111 is a reply to message #544105] Mon, 20 February 2012 04:01 Go to previous messageGo to next message
van_culo
Messages: 6
Registered: February 2012
Location: Milano, Italy
Junior Member
I don't understand what you mean? I don't know if this is a bug, that is why I'm asking. The logical expression is not working as it should according to Java Language Specification, but maybe Oracle does not comply 100% with the Java Specification. But if it is so, with a simple thing as this, then I would like to know if there are more surprises? I do know that i can simply do a work around, but then how many workarounds do I have to do, is this still Java? I would like an explanation if possible. An upgrade of Oracle is out of the question, these are servers installed at clients and I can not make a similar decision for them. I just want to know if someone has a deeper knowledge of as why Oracle is not compliant with the Java Language Specification, can someone please explain this? Do you think this is a bug? If not, is there documentation from Oracle that explains why this is not a bug, are there other limitations? I don't want to report a bug to Oracle if it is already known this limitation or if it is already documented as a limitation. So I'm asking here before doing such a thing.
Re: Java Stored Procedure - if expression [message #544117 is a reply to message #544111] Mon, 20 February 2012 04:18 Go to previous messageGo to next message
Michel Cadot
Messages: 68624
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
can someone please explain this?


Outside Oracle itself? No.

Quote:
Do you think this is a bug?


It depends.
Was this in the standard for version 1.4.2?
Is this a mandatory feature to be compliant with the standard?

Quote:
I don't want to report a bug to Oracle if it is already known this limitation or if it is already documented as a limitation


Then search on MOS but anyway Oracle supports is there to answer such questions.

A last question, are you talking about the Java inside the database engine or the Java compiler outside it (JDBC, SQLJ...)?

Regards
Michel
Re: Java Stored Procedure - if expression [message #544124 is a reply to message #544117] Mon, 20 February 2012 04:40 Go to previous messageGo to next message
van_culo
Messages: 6
Registered: February 2012
Location: Milano, Italy
Junior Member
Thanks for your support.

I don't know if in Oracle it is a mandatory feature to be compliant with the Java Standard, but if not I would like to know which standard to follow.

I am talking about the Java inside the database engine, it is a stored procedure written in Java. First compiled outside Oracle with JDK1.4 of course working fine.

This is in my opinion a big problem because the "if" statement is very frequently used. Of course as mentioned I'm very worried if there could be other limitations because we are now writing stored procedures for our client in Java and we are in the dark about these limitations.

Tim
Re: Java Stored Procedure - if expression [message #544129 is a reply to message #544124] Mon, 20 February 2012 04:58 Go to previous messageGo to next message
Michel Cadot
Messages: 68624
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
If this was my problem, I'd open a SR and ask Oracle support.
You have a clear and concise test case, easy to reproduce, I should not hesitate a second to open a SR.

If you post your test case here, I'll try it on different Oracle versions.
Which one is yours (with 4 decimals)?

Regards
Michel
Re: Java Stored Procedure - if expression [message #544131 is a reply to message #544129] Mon, 20 February 2012 05:07 Go to previous messageGo to next message
van_culo
Messages: 6
Registered: February 2012
Location: Milano, Italy
Junior Member
select * from v$version
where banner like 'Oracle%';

gives

Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi



It seems strange to me that something so obvious has not been detected. But this is a new world to me, and maybe very little people use this feature, or they have discovered it, ignored it and just done a workaround for each problem they have found. Or it's just me, missing something obvious.

Re: Java Stored Procedure - if expression [message #544136 is a reply to message #544131] Mon, 20 February 2012 05:29 Go to previous messageGo to next message
Michel Cadot
Messages: 68624
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Very little people indeed use Java inside the database, the preferred programming language is PL/SQL and only things that can't be with PL/SQL is implemented in Java and most of the time it is not do inside the database but in the application itself.
And, as you said, maybe they just use the workaround, if you have this only a couple of times in your code then it may not be worth to open a SR to Oracle for it (and most often people that develop do not have any support contract with Oracle and so cannot do in other way).
Also, I tried to find some references on MOS but failed to find the correct key words that could lead me to the correct note.

Regards
Michel
Re: Java Stored Procedure - if expression [message #544140 is a reply to message #544136] Mon, 20 February 2012 05:42 Go to previous messageGo to next message
van_culo
Messages: 6
Registered: February 2012
Location: Milano, Italy
Junior Member
Ok thanks, I've written on the newsgroup in Oracle (forums.oracle.com/forums/thread.jspa?threadID=2348960&tstart=0) and hope to have some feedback. The decision to write these procedures are made by our clients so it is not an option to me to make another approach, but it is surprising that a product used so much has so little feedback on a problem so obvious.
Re: Java Stored Procedure - if expression [message #544142 is a reply to message #544140] Mon, 20 February 2012 05:52 Go to previous messageGo to next message
Michel Cadot
Messages: 68624
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
I will follow the thread in Oracle forums.
Can you post a complete (but simple) test case that generates the error and I could reproduce in my environments.

Regards
Michel
Re: Java Stored Procedure - if expression [message #544167 is a reply to message #544142] Mon, 20 February 2012 07:13 Go to previous messageGo to next message
van_culo
Messages: 6
Registered: February 2012
Location: Milano, Italy
Junior Member
Sorry everyone,

I have mad a big mistake. On loading the Java file to Oracle Server, for some reason Oracle decides that the "&&" (and operator) triggers a variable substitution and becomes "&". As so I have the error. I need to "SET DEFINE OFF" upon loading the script, otherwise Oracle makes this substitution.

I hope this thread helps future people with the similar problem. Thank you Michel for you patience.
Re: Java Stored Procedure - if expression [message #544171 is a reply to message #544167] Mon, 20 February 2012 07:25 Go to previous message
Michel Cadot
Messages: 68624
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Ah! Good to know, thanks for your feedback.

Regards
Michel
Previous Topic: xml extract -> xml string-join
Next Topic: help with xmlagg
Goto Forum:
  


Current Time: Thu Mar 28 04:38:16 CDT 2024