One Star

NB_LINE nullpointerexception

Flow: tRESTreq -> tFlowToIter -> tOracleInput -> txmlMap -> tRestResp
In the xmlmap I am trying to perform flow control. For that I would need to distinguish between the number of line (tOracleInput_NB_LINE) being either 0 or 1 to set the condition for different xmlmap outputs. However as I globalMap.get("tOracleinput_3_NB_LINE") I get a nullpointer. 
I had a look at the code and it turns out that for some odd reason the variable scope for the xmlmap definitions is put in before where NB_LINE is inserted into the globalMap (about 50 lines below).
Is there any way around or is this a bug? I have already tried using a tJavaRow between the two components but I get a "cannot refer to non-final variable" error. I cannot use onsubjob either since the code for that component also gets generated and executed after the variable scope of xmlmap.
6 REPLIES
Community Manager

Re: NB_LINE nullpointerexception

The global variable can be only used later on another subjob. With this job design, if you look into the generated code of job, you will see it gets the value before the value is set, that's why you get nullpointer exception. To resolve it, you have to re-design the job, for example:
parent job:
tRestReq->tFlowToIterate--iterate--tRunJob--main-tRestResp
tRunJob: call the child job and pass value from parent job to child job if needed, refer to this KB article.
child job:
tOracleInput--main--tHashOutput
  |
tHashInput--main--tXMLMap--main--tBufferOutput
on tXMLMap, you are able to access the Oracle NB_line varaible.

Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: NB_LINE nullpointerexception

Thanks a lot for the quick reply. I will definitely try your suggestion. 
However in the meantime, Would you happen to know why does the route stop when I get 0 rows out of the database. Since the database contains hundreds of millions of rows, we cannot afford to have a lookup link between oracleinput and xmlmap so I chose this design to be able to include a where clause in the oracleinput and have it return only 1 row (or 0 row in case of no match). However in the case of executing the query and not finding a match in the database (0 rows case) the route actually stops at oracleinput. I am asking this since if it didn't, I would be able to easily have 2 outputs with conditions in the xmlmap checking for the input_row or row1 being null.
One Star

Re: NB_LINE nullpointerexception

So I just implemented it the same way as you suggested before and I am still not getting any results for the no match case. I will try to explain the issue to the best of my abilities.
In the child job, going from oraclein to hashout in the case of no match (0 rows), it seems so that the route completely stops executing. I added a tjavarow between hashin and xmlmap which has some simple system.out and none of them gets printed out in the case of 0 rows but when there is a row coming out of the oraclein they do get printed out.
I am not sure what is happening here at all. It doesn't seem intuitive to me.
Thanks
Community Manager

Re: NB_LINE nullpointerexception

Hi
Is it a rest web service or a route? I have tried to create a rest web service to reproduce the problem, I got the following error if no rows are found. 
Exception in component tRESTClient_1
javax.ws.rs.NotFoundException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at

To resolve this exception, we can customize output message if no rows are found.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: NB_LINE nullpointerexception

Hi,
Here is my design. The top picture is the main job and you see two rows going out from the restRequest. Top row being my original design and the bottom one being the new design using runJob. The bottom picture depicts the job that gets run by the runJob.
As you can see in the pictures there are 0 rows going out in the sub job. This is the case of "no match" in the database. Now here is my question: In the bottom picture I have two outputs in the xmlmap. the getRMUResponse is the usual response but getRMUfault is the top output and has a condition ((Integer) globalMap("tOracleInput_3_NB_LINE)) == 0). This is where I have the error. That key in the globalMap doesnt exist and I get the nullpointer exception. 
How would I be able to fix this? Right now I get an empty response in the case of "no match" in the database and a correct response in the case of a match.  
http://imgur.com/iC69xqy,cVG7Pp9#1      Main job
http://imgur.com/iC69xqy,cVG7Pp9#0      Sub job
Regards
Community Manager

Re: NB_LINE nullpointerexception

Hi
You uploaded two same pictures, I don't know where do you set the expression ((Integer) globalMap("tOracleInput_3_NB_LINE)) == 0), can you please export the job and send it to me for further investigation?
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business