java.lang.IllegalArgumentException: Cannot merge with [org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder]

Spring JIRA | Erich Eichinger | 4 years ago
  1. 0

    The test below fails with: {panel} java.lang.IllegalArgumentException: Cannot merge with [org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder] at org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder.merge(MockMultipartHttpServletRequestBuilder.java:88) at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:123) {panel} Test: {code} public class FileUploadControllerTest { @Controller public class MyFileUploadController { public static final String MULTIPART_FILEUPLOAD = "/multipartfileupload"; @RequestMapping(value = MULTIPART_FILEUPLOAD, method= RequestMethod.POST) public void multipart_fileupload(@RequestParam MultipartFile file, Model model) throws IOException { model.addAttribute("message", "File '" + file.getOriginalFilename() + "' uploaded successfully: " + new String(file.getBytes())); } } @Test public void fileupload_example() throws Exception { MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new MyFileUploadController()) .defaultRequest(get("/").characterEncoding("utf-8")).build(); mockMvc.perform( fileUpload(MULTIPART_FILEUPLOAD) .file("myfilename", "data".getBytes())) .andExpect(model().attribute("message", "File 'myfilename' uploaded successfully")); } } {code} I'd suggest {{MockMultipartHttpServletRequestBuilder#merge()}} allows to be merged with standard {{MockHttpServletRequestBuilder}} instances.

    Spring JIRA | 4 years ago | Erich Eichinger
    java.lang.IllegalArgumentException: Cannot merge with [org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder]
  2. 0

    The test below fails with: {panel} java.lang.IllegalArgumentException: Cannot merge with [org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder] at org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder.merge(MockMultipartHttpServletRequestBuilder.java:88) at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:123) {panel} Test: {code} public class FileUploadControllerTest { @Controller public class MyFileUploadController { public static final String MULTIPART_FILEUPLOAD = "/multipartfileupload"; @RequestMapping(value = MULTIPART_FILEUPLOAD, method= RequestMethod.POST) public void multipart_fileupload(@RequestParam MultipartFile file, Model model) throws IOException { model.addAttribute("message", "File '" + file.getOriginalFilename() + "' uploaded successfully: " + new String(file.getBytes())); } } @Test public void fileupload_example() throws Exception { MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new MyFileUploadController()) .defaultRequest(get("/").characterEncoding("utf-8")).build(); mockMvc.perform( fileUpload(MULTIPART_FILEUPLOAD) .file("myfilename", "data".getBytes())) .andExpect(model().attribute("message", "File 'myfilename' uploaded successfully")); } } {code} I'd suggest {{MockMultipartHttpServletRequestBuilder#merge()}} allows to be merged with standard {{MockHttpServletRequestBuilder}} instances.

    Spring JIRA | 4 years ago | Erich Eichinger
    java.lang.IllegalArgumentException: Cannot merge with [org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder]
  3. 0

    Section _C.2.2.4 <util:list/>_ of the reference manual states: {quote}Finally, you can also control the merging behavior using the 'merge' attribute of the <util:list/> element; collection merging is described in more detail in the section called "Collection merging".{quote} This is, however, not true. In contrast to the standard support for collections (i.e., array, list, set, map) in the _beans_ namespace, the _util_ namespace does not support the merge attribute for collections. Is this an oversight in the documentation or missing functionality in the util namespace support? On a related note (perhaps worthy of its own JIRA issue), given the following application context configuration and JUnit test class... {code} <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"> <bean id="listHolderParent" class="com.example.MergedListTests$ListHolder" abstract="true"> <property name="list"> <list> <value>red</value> <value>green</value> <value>blue</value> </list> </property> </bean> <bean id="listHolder" parent="listHolderParent"> <property name="list"> <list merge="true"> <value>cyan</value> <value>magenta</value> <value>yellow</value> <value>black</value> </list> </property> </bean> </beans> {code} {code} package com.example; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.util.List; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class MergedListTests { @Test public void mergedList() { ApplicationContext appCtx = new ClassPathXmlApplicationContext( "/com/example/MergedListTests-context.xml"); ListHolder listHolder = appCtx.getBean("listHolder", ListHolder.class); assertNotNull(listHolder); assertEquals(7, listHolder.getList().size()); } public static class ListHolder { private List<String> list; public List<String> getList() { return this.list; } public void setList(List<String> list) { this.list = list; } } } {code} ... changing the *<list>* definition in _listHolderParent_ to *<util:list>* results in the following exception: {quote} java.lang.IllegalArgumentException: Cannot merge with object of type [class org.springframework.beans.factory.config.BeanDefinitionHolder] at org.springframework.beans.factory.support.ManagedList.merge(ManagedList.java:98) at org.springframework.beans.factory.support.ManagedList.merge(ManagedList.java:1) at org.springframework.beans.MutablePropertyValues.mergeIfRequired(MutablePropertyValues.java:221) at org.springframework.beans.MutablePropertyValues.addPropertyValue(MutablePropertyValues.java:169) at org.springframework.beans.MutablePropertyValues.addPropertyValues(MutablePropertyValues.java:138) at org.springframework.beans.factory.support.AbstractBeanDefinition.overrideFrom(AbstractBeanDefinition.java:300) at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:1114) at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:1054) at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1040) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:294) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:578) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:398) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) at com.example.MergedListTests.mergedList(MergedListTests.java:17) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ...{quote}

    Spring JIRA | 7 years ago | Sam Brannen
    java.lang.IllegalArgumentException: Cannot merge with object of type [class org.springframework.beans.factory.config.BeanDefinitionHolder]
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Section _C.2.2.4 <util:list/>_ of the reference manual states: {quote}Finally, you can also control the merging behavior using the 'merge' attribute of the <util:list/> element; collection merging is described in more detail in the section called "Collection merging".{quote} This is, however, not true. In contrast to the standard support for collections (i.e., array, list, set, map) in the _beans_ namespace, the _util_ namespace does not support the merge attribute for collections. Is this an oversight in the documentation or missing functionality in the util namespace support? On a related note (perhaps worthy of its own JIRA issue), given the following application context configuration and JUnit test class... {code} <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"> <bean id="listHolderParent" class="com.example.MergedListTests$ListHolder" abstract="true"> <property name="list"> <list> <value>red</value> <value>green</value> <value>blue</value> </list> </property> </bean> <bean id="listHolder" parent="listHolderParent"> <property name="list"> <list merge="true"> <value>cyan</value> <value>magenta</value> <value>yellow</value> <value>black</value> </list> </property> </bean> </beans> {code} {code} package com.example; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.util.List; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class MergedListTests { @Test public void mergedList() { ApplicationContext appCtx = new ClassPathXmlApplicationContext( "/com/example/MergedListTests-context.xml"); ListHolder listHolder = appCtx.getBean("listHolder", ListHolder.class); assertNotNull(listHolder); assertEquals(7, listHolder.getList().size()); } public static class ListHolder { private List<String> list; public List<String> getList() { return this.list; } public void setList(List<String> list) { this.list = list; } } } {code} ... changing the *<list>* definition in _listHolderParent_ to *<util:list>* results in the following exception: {quote} java.lang.IllegalArgumentException: Cannot merge with object of type [class org.springframework.beans.factory.config.BeanDefinitionHolder] at org.springframework.beans.factory.support.ManagedList.merge(ManagedList.java:98) at org.springframework.beans.factory.support.ManagedList.merge(ManagedList.java:1) at org.springframework.beans.MutablePropertyValues.mergeIfRequired(MutablePropertyValues.java:221) at org.springframework.beans.MutablePropertyValues.addPropertyValue(MutablePropertyValues.java:169) at org.springframework.beans.MutablePropertyValues.addPropertyValues(MutablePropertyValues.java:138) at org.springframework.beans.factory.support.AbstractBeanDefinition.overrideFrom(AbstractBeanDefinition.java:300) at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:1114) at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:1054) at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1040) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:294) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:578) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:398) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) at com.example.MergedListTests.mergedList(MergedListTests.java:17) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ...{quote}

    Spring JIRA | 7 years ago | Sam Brannen
    java.lang.IllegalArgumentException: Cannot merge with object of type [class org.springframework.beans.factory.config.BeanDefinitionHolder]
  6. 0

    Exception during merging linear/multidimensional positions

    GitHub | 2 years ago | thorsten-k
    java.lang.IllegalArgumentException: Cannot merge linear position and multidimensionl positions

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalArgumentException

      Cannot merge with [org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder]

      at org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder.merge()
    2. Spring TestContext
      MockMvc.perform
      1. org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder.merge(MockMultipartHttpServletRequestBuilder.java:88)
      2. org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:123)
      2 frames