• Post Reply Bookmark Topic Watch Topic
  • New Topic

Null pointer exception while calling oracle.sql.STRUCT;  RSS feed

 
nitinram agarwal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am getting the following exception

  • java.lang.NullPointerException
    at oracle.jdbc.oracore.OracleTypeADT.getAttributeName(OracleTypeADT.java:2243)
    at oracle.sql.StructDescriptor.toOracleArray(StructDescriptor.java:747)
    at oracle.sql.STRUCT.<init>(STRUCT.java:200)


  • when I make the call as


    The if block is never entered and hence it might be some internal attribute/objects within this object which is causing the NPE.

    Any idea what might be the reason?

    Regards.
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 66304
    152
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Where are your braces around the if and else blocks? No braces == FAIL.
     
    Jeff Verdegan
    Bartender
    Posts: 6109
    6
    Android IntelliJ IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    This tells you that you passed a null to the STRUCT constructor where a null is not allowed:


    This: and this: suggest very strongly that itemDescriptor is null.


    And also, what Bear said, times infinity.
     
    nitinram agarwal
    Ranch Hand
    Posts: 90
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator


    the above if prints
    not null


    so the question is why this statement is throwing NPE

     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 66304
    152
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Logic fail. Not all your null tests may complete. Why the circuitous if tests?

    Just do something like:

    System.out.println("Whatever=" + whatever);

    (Or better yet, use logging rather than System.out).
     
    nitinram agarwal
    Ranch Hand
    Posts: 90
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I am just putting something in my dev environment.. Its not final code..
    the code is still in development but is failing for one particular data type and I am trying to understand.. it works fine for other data type which I am supporting..

    I am just trying to understand if there is a ready idea on why NPE is being thrown by the OracleTypeADT class. The documentation on the API page.. I could not make out much. So reaching out to forum

    Regards
     
    Jeff Verdegan
    Bartender
    Posts: 6109
    6
    Android IntelliJ IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    nitinram agarwal wrote:
    the above if prints
    not null


    so the question is why this statement is throwing NPE


    Either you're passing null to the constructor, or there's something external that it depends on that's null.

    Is that if/else immediately before the new STRUCT() line? And are you sure you don't have other similarly named variables somewhere so that you might be missing a spelling difference? Or locals hiding members?

    I would do it like this:


    And I would copy/paste from each of my print statements onto the constructor args.

    Maybe itemDescriptor names some type that STRUCT doesn't have a mapping for, or pos indicates a position in the descriptor that's not been populated. I'm guessing at what those args mean and what STRUCT is and how they all relate, more to give you an idea of what kinds of thing to investigate than as any real, informed diagnosis.

     
    nitinram agarwal
    Ranch Hand
    Posts: 90
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator


    it prints the following

    itemDescriptor=oracle.sql.StructDescriptor@1bf8cd5
    conn=oracle.jdbc.driver.T4CConnection@16c75ed
    pos={inst_vndr_id=$AAAAAA0, currency_code=USD, price_ind=S, .........


     
    Don't get me started about those stupid light bulbs.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!