HAN BEI created OLINGO-1398: ------------------------------- Summary: got IllegalArgumentException in spring boot Key: OLINGO-1398 URL: https://issues.apache.org/jira/browse/OLINGO-1398 Project: Olingo Issue Type: Bug Components: odata2-annotation Affects Versions: V2 2.0.11 Reporter: HAN BEI Attachments: bug.jpg
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 jarva -jar xxx. I made some changes to fix this issue temporarily: {code:java} 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); } } } } {code} -- This message was sent by Atlassian Jira (v8.3.2#803003)