Ivana
Ivana

Reputation: 705

Spring: ArrayIndexOutOfBoundsException during context initialization

I have a Spring-boot application which throws an ArrayIndexOutOfBoundsException during context initialization. This happens somewhere deep in the bowels of Spring.

I've located the cause to ConfigurationClassParser, method processDeferredImportSelectors, line 547:

String[] imports = deferredImport.getImportSelector().selectImports(configClass.getMetadata());

This will call selectImports of AutoConfigurationImportSelector, which in turn calls the private method sort, which will instantiate a SimpleMetadataReader, and this will throw the exception in line 65:

classReader.accept(visitor, ClassReader.SKIP_DEBUG);

The resource where it goes wrong is: SerializationDataFormatAutoConfiguration.class, this is a camel class from the package org.apache.camel.impl.springboot package.

I'm not sure if it's some kind of dependency clash, or an error in my components or in my .yml properties file.

My pom is:

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
  http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>nl.mycompany.camel</groupId>
 <artifactId>camel-verne-prophet-splitter</artifactId>
 <packaging>jar</packaging>
  <version>1.0.1</version>
 <name>camel-verne-prophet-splitter</name>
 <description>bla</description>
  <properties>
    <mycompany.camel.utils.version>1.46</mycompany.camel.utils.version>
    <project.mainClass>
       nl.mycompany.camel.verneprophetsplitter.StartUpVerneProphet
    </project.mainClass>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <camel.version>2.20.2</camel.version>
    <camel.jcifs.version>2.18.0</camel.jcifs.version>
    <jcifs.version>1.3.18-mycompany</jcifs.version>
    <maven.checkstyle.version>2.16</maven.checkstyle.version>
    <maven.pmd.version>3.6</maven.pmd.version>
    <target.jdk>1.8</target.jdk>
    <svnBinariesDir>forSvnBinaries</svnBinariesDir>
    <shadedResultFile>
       ${project.artifactId}-${project.version}.jar
      </shadedResultFile>
    <pitest.version>1.1.5</pitest.version>
    </properties>

       <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
 </parent>

         <dependencies>
           <dependency>
             <groupId>junit</groupId>
           <artifactId>junit</artifactId>
         <!-- Version managed by parent pom -->
        <scope>test</scope>
      </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-spring-boot-starter</artifactId>
        <version>${camel.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-spring</artifactId>
        <version>${camel.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-quartz2</artifactId>
        <version>${camel.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache-extras.camel-extra</groupId>
        <artifactId>camel-jcifs</artifactId>
        <version>${camel.jcifs.version}</version>
    </dependency>
    <dependency>
        <groupId>jcifs</groupId>
        <artifactId>jcifs</artifactId>
        <version>${jcifs.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-mail</artifactId>
        <version>${camel.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-spring-javaconfig</artifactId>
        <version>${camel.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-ftp</artifactId>
        <version>${camel.version}</version>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
        <!-- Allows the routes to be run via 'mvn camel:run' -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>${target.jdk}</source>
                <target>${target.jdk}</target>
                <encoding>${project.build.sourceEncoding}</encoding>
                <showDeprecation>true</showDeprecation>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-maven-plugin</artifactId>
            <configuration>
                <basedPackages>
                  nl.mycompany.camel.verneprophetsplitter.config
               </basedPackages>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>${maven.checkstyle.version}</version>
            <configuration>
                <configLocation>checkstyle.xml</configLocation>
                 <suppressionsLocation>
                   checkstyle-suppressions.xml
                 </suppressionsLocation>
                 <suppressionsFileExpression>
                    checkstyle.suppressions.file
                </suppressionsFileExpression>
                <includeTestSourceDirectory>true</includeTestSourceDirectory>
            </configuration>
            <executions>
                <execution>
                    <phase>verify</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-pmd-plugin</artifactId>
            <version>${maven.pmd.version}</version>
            <configuration>
                <linkXref>false</linkXref>
                <minimumTokens>100</minimumTokens>
                <targetJdk>${target.jdk}</targetJdk>
                <rulesets>
                    <ruleset>pmd-ruleset.xml</ruleset>
                </rulesets>
                <includeTests>true</includeTests>
            </configuration>
            <executions>
                <execution>
                    <phase>verify</phase>
                    <goals>
                        <goal>check</goal>
                        <goal>cpd-check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <excludes>
                    <exclude>**/logback.xml</exclude>
                    <exclude>**/*.yml</exclude>
                </excludes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <configuration>
                <filesets>
                    <fileset>
                        <directory>${svnBinariesDir}</directory>
                    </fileset>
                </filesets>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${svnBinariesDir}</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/resources</directory>
                                <includes>
                                    <include>*.*</include>
                                </includes>
                                <filtering>true</filtering>
                            </resource>
                            <resource>
                                <directory>target</directory>
                                <includes>
                                    <include>${shadedResultFile}</include>
                                </includes>
                            </resource>
                            <resource>
                                <directory>${basedir}</directory>
                                <includes>
                              <include>StartVerneProphetSplitter.*</include>
                                </includes>
                                <filtering>true</filtering>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.pitest</groupId>
            <artifactId>pitest-maven</artifactId>
            <version>${pitest.version}</version>
            <configuration>
                <timestampedReports>false</timestampedReports>
                <reportsDirectory>pitest_reports</reportsDirectory>
                <targetClasses>
                    <param>nl.mycompany.camel.verneprophetsplitter.*</param>
                </targetClasses>
                <targetTests>
                    <param>nl.mycompany.camel.verneprophetsplitter.*</param>
                </targetTests>
                <jvmArgs>
                    <value>-Xmx512m</value>
                    <value>-XX:MaxPermSize=128m</value>
                </jvmArgs>
                <timeoutConstant>20000</timeoutConstant>
                <historyInputFile>pitests/history</historyInputFile>
                <historyOutputFile>pitests/history</historyOutputFile>
            </configuration>
        </plugin>
    </plugins>
</build>

 <reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-maven-plugin</artifactId>
            <configuration>
                <finalName>camel-verne-prophet-splitter</finalName>
                <outputDirectory>target</outputDirectory>
            </configuration>
        </plugin>
    </plugins>
 </reporting>
</project>

My application.yml is just:

from: from
to: to

And my configuration class is:

package nl.mycompany.camel.verneprophetsplitter.config;

 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.context.annotation.Configuration;

 /**
  * Configuration for the verne-prophet application.
  *
  */
  @Configuration
  @ConfigurationProperties
  public class ApplicationConfig {

   private String from;
   private String to;


   /**
    * @return the from
    */
   public String getFrom() {
       return from;
   }

   /**
    * @param aFrom the from to set
    */
   public void setFrom(String aFrom) {
       from = aFrom;
   }

   /**
    * @return the to
    */
   public String getTo() {
       return to;
   }

   /**
   * @param aTo the to to set
   */
   public void setTo(String aTo) {
      to = aTo;
   }


}

Upvotes: 0

Views: 757

Answers (2)

Ivana
Ivana

Reputation: 705

Based on both the answer and the comment by Claus Ibsen, i managed to get it working with version 1.5.10.RELEASE of Spring-boot and 2.18.0 of camel.

In addition, eclipse seems to have a cache that is not always updated. The most efficient way to deal with this type of problem seems to be command line with maven. First get it working, using mvn clean eclipse:clean eclipse:eclipse and mvn install between trying different combinations of versions.

Upvotes: 0

Claus Ibsen
Claus Ibsen

Reputation: 55750

Ah didnt spot the first time that you are using Spring Boot 2.0.

Apache Camel is not compatible with Spring Boot 2, and you must use Spring Boot 1.5.x.

Support for Spring Boot 2 is planned for the Apache Camel 2.22 release which comes in summer 2018.

Upvotes: 1

Related Questions