Coder Social home page Coder Social logo

Helidon 4.0.7: Parameters.first(String) generates java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0 about helidon HOT 6 CLOSED

hrstoyanov avatar hrstoyanov commented on June 11, 2024
Helidon 4.0.7: Parameters.first(String) generates java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0

from helidon.

Comments (6)

talios avatar talios commented on June 11, 2024

I hit something similar to this the other day and worked around it with:

var query = req.query();
if (!query.isEmpty() && query.get("period") instanceof String period) {

Having to check the isEmpty is kind-of a pain. Tho the out-of-bounds you got seems worse.

from helidon.

hrstoyanov avatar hrstoyanov commented on June 11, 2024

@talios have you tried:

var period = req.query().first("period").asString().orElse("whatever);

//or

req
    .query()
    .first("period")
    .asString()
    .ifPresent(period->{....});

from helidon.

talios avatar talios commented on June 11, 2024

@hrstoyanov That works nicely - even better using .as(Period::parse) to map to the desired type. Much cleaner - cheers!

from helidon.

tomas-langer avatar tomas-langer commented on June 11, 2024

Reason for this bug is that the implementation did not expect an empty list as a value in the map used to create it.
The place we introduced this (I think the only one) is in URI Query, where we handle the case of a parameter without a follow-up = as a name without a value - so contains returns true, but there is no value.
So we were missing a validation of the map for the assumption of the implementation, and a change once we decided to support it.
The only sloppiness I see here is the lack of test for a query parameter without a value...

from helidon.

hrstoyanov avatar hrstoyanov commented on June 11, 2024

@tomas-langer apologies, the code is actaully very nicely designed maybe needs unit test, I updated the initial report. Sorry!

from helidon.

jbescos avatar jbescos commented on June 11, 2024

Merged, thank you for reporting it

from helidon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.