@Nullable private InputStream inputStreamFor(String fullname) { return classLoader.getResourceAsStream(Convert.bytecodeName(fullname) + ".class"); }
@Nullable private InputStream inputStreamFor(String fullname) { return classLoader.getResourceAsStream(Convert.bytecodeName(fullname) + ".class"); }
@Nullable private InputStream inputStreamFor(String fullname) { return getClassLoader().getResourceAsStream(Convert.bytecodeName(fullname) + ".class"); }
@Nullable private InputStream inputStreamFor(String fullname) { return getClassLoader().getResourceAsStream(Convert.bytecodeName(fullname) + ".class"); }
/** * Read bytes representing class with name passed as an argument. Modify the class version in bytecode so ASM can read * returned array without issues. * * @param className canonical name of the class (e.g. org.acme.Foo ) * @return bytes or null if class is not found */ @CheckForNull public byte[] getBytesForClass(String className) { try (InputStream is = getResourceAsStream(Convert.bytecodeName(className) + ".class")) { if (is == null) { return null; } return ByteStreams.toByteArray(is); } catch (IOException e) { throw new AnalysisException("An IOException occurred in SonarJava classLoader.",e); } }
/** * Read bytes representing class with name passed as an argument. Modify the class version in bytecode so ASM can read * returned array without issues. * * @param className canonical name of the class (e.g. org.acme.Foo ) * @return bytes or null if class is not found */ @CheckForNull public byte[] getBytesForClass(String className) { try (InputStream is = getResourceAsStream(Convert.bytecodeName(className) + ".class")) { if (is == null) { return null; } return ByteStreams.toByteArray(is); } catch (IOException e) { throw new AnalysisException("An IOException occurred in SonarJava classLoader.",e); } }
/** * <b>Note:</b> Attempt to find something like "java.class" on case-insensitive file system can result in unwanted loading of "JAVA.class". * This method performs check of class name within file in order to avoid such situation. * This is definitely not the best solution in terms of performance, but acceptable for now. * * @return symbol for requested class, if corresponding class file exists, and {@link org.sonar.java.resolve.Resolve.JavaSymbolNotFound} otherwise */ // TODO(Godin): Method name is misleading because of lazy loading. public JavaSymbol loadClass(String fullname) { JavaSymbol.TypeJavaSymbol symbol = classes.get(fullname); if (symbol != null) { return symbol; } byte[] bytesForClass = classLoader.getBytesForClass(fullname); if (bytesForClass == null) { return new Resolve.JavaSymbolNotFound(); } ClassReader classReader = new ClassReader(bytesForClass); String className = classReader.getClassName(); if (!className.equals(Convert.bytecodeName(fullname))) { return new Resolve.JavaSymbolNotFound(); } return getClassSymbol(fullname); }
String bytecodeName = Convert.bytecodeName(fullname);
String bytecodeName = Convert.bytecodeName(fullname);
/** * <b>Note:</b> Attempt to find something like "java.class" on case-insensitive file system can result in unwanted loading of "JAVA.class". * This method performs check of class name within file in order to avoid such situation. * This is definitely not the best solution in terms of performance, but acceptable for now. * * @return symbol for requested class, if corresponding class file exists, and {@link org.sonar.java.resolve.Resolve.JavaSymbolNotFound} otherwise */ // TODO(Godin): Method name is misleading because of lazy loading. public JavaSymbol loadClass(String fullname) { JavaSymbol.TypeJavaSymbol symbol = classes.get(fullname); if (symbol != null) { return symbol; } byte[] bytesForClass = classLoader.getBytesForClass(fullname); if (bytesForClass == null) { return new Resolve.JavaSymbolNotFound(); } ClassReader classReader = new ClassReader(bytesForClass); String className = classReader.getClassName(); if (!className.equals(Convert.bytecodeName(fullname))) { return new Resolve.JavaSymbolNotFound(); } return getClassSymbol(fullname); }
case JavaType.CLASS: case JavaType.UNKNOWN: return org.objectweb.asm.Type.getObjectType(Convert.bytecodeName(javaType.fullyQualifiedName())); case JavaType.ARRAY: JavaType element = ((ArrayJavaType) javaType).elementType;
case JavaType.CLASS: case JavaType.UNKNOWN: return org.objectweb.asm.Type.getObjectType(Convert.bytecodeName(javaType.fullyQualifiedName())); case JavaType.ARRAY: JavaType element = ((ArrayJavaType) javaType).elementType;
JavaSymbol.TypeJavaSymbol getClassSymbol(String bytecodeName, int flags) { String flatName = Convert.flatName(bytecodeName); JavaSymbol.TypeJavaSymbol symbol = classes.get(flatName); if (symbol == null) { String shortName = Convert.shortName(flatName); String packageName = Convert.packagePart(flatName); String enclosingClassName = Convert.enclosingClassName(shortName); if (StringUtils.isNotEmpty(enclosingClassName)) { //handle innerClasses symbol = new JavaSymbol.TypeJavaSymbol(filterBytecodeFlags(flags), Convert.innerClassName(shortName), getClassSymbol(Convert.fullName(packageName, enclosingClassName))); } else { symbol = new JavaSymbol.TypeJavaSymbol(filterBytecodeFlags(flags), shortName, enterPackage(packageName)); } symbol.members = new Scope(symbol); symbol.typeParameters = new Scope(symbol); // (Godin): IOException will happen without this condition in case of missing class: if (getClassLoader().getResource(Convert.bytecodeName(flatName) + ".class") != null) { symbol.completer = this; } else { LOG.error("Class not found: " + bytecodeName); ((JavaType.ClassJavaType) symbol.type).interfaces = ImmutableList.of(); ((JavaType.ClassJavaType) symbol.type).supertype = Symbols.unknownType; } classes.put(flatName, symbol); } return symbol; }
if (classLoader.getResource(Convert.bytecodeName(flatName) + ".class") != null) { symbol.completer = this; } else {
if (classLoader.getResource(Convert.bytecodeName(flatName) + ".class") != null) { symbol.completer = this; } else {
if (getClassLoader().getResource(Convert.bytecodeName(flatName) + ".class") != null) { symbol.completer = this; } else {