Uploaded image for project: 'Olingo'
  1. Olingo
  2. OLINGO-1398

got IllegalArgumentException in spring boot

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • V2 2.0.11
    • V2 2.0.12
    • odata2-annotation
    • None

    Description

      I got IllegalArgumentException in spring boot. That is beacause in spring boot we package third party dependency as embed jar. The url would be like this:jar:file:/C:/works/project/intelligent-claims/code/claims-web/target/sap-claims-service.jar!/BOOT-INF/lib/claims-api-0.0.1-SNAPSHOT.jar!/com/sap/s4/eureka/claims/api/v1/ro/masterdata. org.apache.olingo.odata2.annotation.processor.core.util.ClassHelper.getClassFqnFromJar(URI, String) can not handle this url

      correctly because split.length is 3 not 2 and JarFile(jarFilePath) can not handle embed jar path correctly. Please test and reproduce this issue in spring boot fat jar use java -jar xxx.

      I made some changes to fix this issue temporarily:

       

        private static Collection<String> getClassFqnFromJar(final URI uri, final String packageToScan) {  private static Collection<String> getClassFqnFromJar(final URI uri, final String packageToScan) {    final String jarFilePath;    String filepath = uri.toString();    String[] split = filepath.split(JAR_RESOURCE_SEPARATOR);    if (split.length > 1) {     jarFilePath = filepath.substring(0, filepath.lastIndexOf("!")+2);    } else {      throw new IllegalArgumentException("Illegal jar file path '" + filepath + "'.");    }        JarFile jarFile = null;    try {      URL url = new URL(jarFilePath);      JarURLConnection connection = (JarURLConnection) url.openConnection();      jarFile = connection.getJarFile();      List<String> classFileNames = new ArrayList<String>();      Enumeration<JarEntry> entries = jarFile.entries();
            while (entries.hasMoreElements()) {        JarEntry je = entries.nextElement();        String name = je.getName();        if (!je.isDirectory() && name.matches(".*" + packageToScan + ".*" + CLASSFILE_ENDING)) {          String className = name.substring(0, name.length() - CLASSFILE_ENDING.length());          classFileNames.add(className.replace(RESOURCE_SEPARATOR, PACKAGE_SEPARATOR));        }      }
            return classFileNames;    } catch (IOException e) {      throw new IllegalArgumentException("Exception during class loading from path '" + jarFilePath +          "' with message '" + e.getMessage() + "'.", e);    } finally {      if (jarFile != null) {        try {          jarFile.close();        } catch (IOException e) {          throw new RuntimeException("Error during close of jar file: " + jarFile.getName() + "", e);        }      }    }  }
      

       

       

      Attachments

        1. bug.jpg
          173 kB
          HAN BEI
        2. 0001-OLINGO-1398.patch
          2 kB
          HAN BEI

        Activity

          People

            mirbo mibo
            hb1984 HAN BEI
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: