Home Help Center

NullPointerException

nightndaynightnday Member David ChuOrganization: UofHProject: FlightOp
Language: Java

I am getting NullPointerException when I am sending a request to the server with a parameter containing uninitialized data structure.

I will get an exception at the on the client-side data structure class __write method.

How can I pass in a null data structure and not get an NullPointerException? Is this a limitation of ICE?

The only other choice is to create a flag to indicate valid/invalid data in the data structure and allocate memory for the data structure.

I am using ICE version 3.0.1.

Thanks for any help.
David T.
Student
Java GUI client communicates to C++ server to pull data to display to user.

Comments

  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi,

    Welcome to the forums! We'll be happy to answer your question if you set your signature as you described in this [thread=1697]thread 1697[/thread].

    Cheers,
    Benoit.
  • acbellacbell Member Andrew BellOrganization: Iowa State UniversityProject: National Resources Inventory ✭✭
    Post Some Code

    You might post a little code to show what you are doing, but in general, there is no representation of NULL in ICE. You can have a NULL reference (which is what I think what you mean), but you can't have something like a NULL integer. Many languages don't support NULL in this way.

    Cheers,
  • nightndaynightnday Member David ChuOrganization: UofHProject: FlightOp
    I am referring to complex data structure and not primitive data type (i.e. int, float, ...)

    Assuming that I have the following data structures

    struct AddressType
    {
    int streetNum;
    string streetName;
    ....
    };

    struct PersonType
    {
    string firstName;
    string lastName;
    AddressType address;
    ...
    };

    Assuming that I send a request with the PersonType as a params with the member field address assigns to null.
    I will get an NullPointerException at AddressType.__write()

    Since the generated code does not taken into account that the field is null and tries to access __write() method, the Exception occurs.

    Hope that help.
    __________________
    David Tom
    Student
    Data Validator
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    Can you please update your signature as explained in this thread?
  • nightndaynightnday Member David ChuOrganization: UofHProject: FlightOp
    Ok!

    Hope I can get some answers!!!
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    Sorry David, but I still have to ask you to update your signature as specified in the thread mentioned before. In particular, please include "The name of your company or organization (such as universities), including a Web address (URL)."
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    Thank you for updating your signature.

    You cannot pass null for structs, since structs have value semantics, not reference semantics. For example, for the Slice-to-C++ mapping, Slice structs are translated to C++ structs which are passed by value.

    Instead of structs, you can use classes, which have reference semantics. For a discussion of structs vs. classes, please see the Ice manual, chapter 4.11.6 "Classes Versus Structures".
  • nightndaynightnday Member David ChuOrganization: UofHProject: FlightOp
    Thank you, I will look into the chapter
Sign In or Register to comment.