Skip to content

IndexOutOfBoundException if no media type configurations registered #1657

@EarthCitizen

Description

@EarthCitizen

Our application needs to create a RestTemplate bean unrelated to HATEOAS:

@Bean
public RestTemplate restTemplate() {
    return new RestTemplate();
}

But spring-hateoas is interfering with this bean unexpectedly and unwantedly:

Caused by: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64) ~[na:na]
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70) ~[na:na]
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266) ~[na:na]
	at java.base/java.util.Objects.checkIndex(Objects.java:359) ~[na:na]
	at java.base/java.util.ArrayList.get(ArrayList.java:427) ~[na:na]
	at org.springframework.hateoas.config.WebConverters.augment(WebConverters.java:121) ~[spring-hateoas-1.3.3.jar:1.3.3]
	at org.springframework.hateoas.config.WebConverters.augmentClient(WebConverters.java:87) ~[spring-hateoas-1.3.3.jar:1.3.3]
	at org.springframework.hateoas.config.HypermediaRestTemplateConfigurer.registerHypermediaTypes(HypermediaRestTemplateConfigurer.java:47) ~[spring-hateoas-1.3.3.jar:1.3.3]
	at org.springframework.hateoas.config.RestTemplateHateoasConfiguration$HypermediaRestTemplateBeanPostProcessor.postProcessBeforeInitialization(RestTemplateHateoasConfiguration.java:73) ~[spring-hateoas-1.3.3.jar:1.3.3]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:422) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602) ~[spring-beans-5.3.9.jar:5.3.9]
	... 113 common frames omitted

When looking at WebConverters.augment(WebConverters.java:121), I find this:

Class<?> rootType = infos.get(0).getRootType();

Our application needs to disable all provided forms HypermediaMappingInformation to disable their ObjectMapper mixins, and is doing the following to do that:

@EnableHypermediaSupport(type = {})

It would seem that spring-hateoas makes the incorrect assumption that there will always be at least one HypermediaMappingInformation defined, despite making it possible to define none.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions