int (File dir, final InstrumentationClassFinder finder) { int instrumented = 0; final File[] files = dir.listFiles(); for (File file : files) { final String name = file.getName(); if (name.endsWith(".class")) { final String path = file.getPath(); log("Adding @NotNull assertions to " + path, Project.MSG_VERBOSE); try { final FileInputStream inputStream = new FileInputStream(file); try { FailSafeClassReader reader = new FailSafeClassReader(inputStream); int version = InstrumenterClassWriter.getClassFileVersion(reader); if ((version & 0xFFFF) >= Opcodes.V1_5 && !shouldBeSkippedByAnnotationPattern(reader)) { ClassWriter writer = new InstrumenterClassWriter(reader, InstrumenterClassWriter.getAsmClassWriterFlags(version), finder); if (NotNullVerifyingInstrumenter.processClassFile(reader, writer, myNotNullAnnotations.split(";"))) { final FileOutputStream fileOutputStream = new FileOutputStream(path); try { fileOutputStream.write(writer.toByteArray()); instrumented++; } finally { fileOutputStream.close(); } } } } finally { inputStream.close(); } } catch (IOException e) { log("Failed to instrument @NotNull assertion for " + path + ": " + e.getMessage(), Project.MSG_WARN); } catch (Exception e) { fireError("@NotNull instrumentation failed for " + path + ": " + e.toString()); } } else if (file.isDirectory()) { instrumented += instrumentNotNull(file, finder); } } return instrumented; }