+ Reply to Thread
Results 1 to 7 of 7

Thread: [Feature Request] Custom ES RuntimeException for EsObject.get*

  1. #1
    Member
    Join Date
    Mar 2012
    Posts
    44
    Thanks
    8
    Thanked 1 Time in 1 Post

    [Feature Request] Custom ES RuntimeException for EsObject.get*

    ES guys,

    If I call a EsObject get* method with a variable name that doesn't exit, ES throws a RuntimeException. The problem is that it isn't possible to distinguish it from another RuntimeException (NullPointerException, IllegalArgumentException, HibernateException, to name a few) in the same try catch block.

    The solution I found is to isolate all the get* methods in a single try catch block, but it would be more elegant if you throw a more specific RuntimeException like EsInvalidVariableNameException or something like that.

    Let me know what you think.

  2. #2
    Former Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,664
    Thanks
    83
    Thanked 1,163 Times in 1,151 Posts
    I assume that this is with the Java server api? What we already have is a two parameter getter, where you can specify a default value. I'll add a ticket to throw a custom exception, but what I've found most helpful is just being able to provide the default value to be used if the variable isn't found.
    Teresa Carrigan
    Senior Software Developer
    Janus Research Group, Inc.
    previously
    Senior Engineer
    Electrotank, Inc.

  3. The Following User Says Thank You to tcarr For This Useful Post:

    butaca (05-02-2012)

  4. #3
    Member
    Join Date
    Mar 2012
    Posts
    44
    Thanks
    8
    Thanked 1 Time in 1 Post
    Yes, I'm taking about the Java server API.

    The disadvantage of the two parameter getter with a default value is that an exception isn't thrown. The message could be malformed due to a client programming error or an eventual attack to the server.

    Thanks again.

  5. #4
    Former Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,664
    Thanks
    83
    Thanked 1,163 Times in 1,151 Posts
    Ticket added, and it shouldn't be a difficult fix, for just the server api (might get client Java too by default).

    What I've done in a lot of cases for an integer is make the default -1, then I check to see if the value is -1 later. For a string, make it "", ditto. Your suggestion is a good one, and we will do that.
    Teresa Carrigan
    Senior Software Developer
    Janus Research Group, Inc.
    previously
    Senior Engineer
    Electrotank, Inc.

  6. #5
    Member
    Join Date
    Mar 2012
    Posts
    44
    Thanks
    8
    Thanked 1 Time in 1 Post
    Thanks for the ticket.

    The problem with the -1 thing, is that maybe the message actually had a -1. In this case you don't know if the -1 was the data in the message or the default value. (Let -1 be, *any* default value).

    Thanks again.

  7. #6
    Former Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,664
    Thanks
    83
    Thanked 1,163 Times in 1,151 Posts
    Yeah, that doesn't work if -1 is a valid value. Mostly I was using it in cases where I was expecting a positive integer, such as an id number.
    Teresa Carrigan
    Senior Software Developer
    Janus Research Group, Inc.
    previously
    Senior Engineer
    Electrotank, Inc.

  8. #7
    Former Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,664
    Thanks
    83
    Thanked 1,163 Times in 1,151 Posts
    This has been implemented as EsObjectVariableNotFoundException, and the error message thrown now includes the EsObject.toString as well for easier debugging.
    Teresa Carrigan
    Senior Software Developer
    Janus Research Group, Inc.
    previously
    Senior Engineer
    Electrotank, Inc.

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts