Skip to content

Helidon 4.0.7: Parameters.first(String) generates java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0 #8710

Closed
@hrstoyanov

Description

Environment Details

  • Helidon Version: 4.0.7
  • Helidon SE
  • JDK version: 21.0.2
  • OS: MacOS

The implementation of Parameters.first(String) has some issues: As it returns an optional value, it should never fail:

       var content = req.content();
        if(content.hasEntity()){
            var params = content.as(Parameters.class);
            var q = params.first("q");
            if(q.isPresent()) {
                ...
            }
        }

... and here is the failure stack trace:

Caused by: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:100)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:106)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:302)
	at java.base/java.util.Objects.checkIndex(Objects.java:385)
	at java.base/java.util.ArrayList.get(ArrayList.java:427)
	at io.helidon.common.parameters@4.0.7/io.helidon.common.parameters.ParametersMap.get(ParametersMap.java:70)
	at io.helidon.common.parameters@4.0.7/io.helidon.common.parameters.ParametersMap.first(ParametersMap.java:101)

If you follow the stack trace, you will see the problem. My current workaround is to convert to a Map:

var content = req.content();
if(content.hasEntity()) {
     var params = content.as(Parameters.class).toMap();
      ...
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

  • Status

    Closed

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions