Attribute (ClassWriter cw, Method method, byte[] bytecodes, boolean withLineNumbers) { return createAttribute("Code", dos -> { dos.writeShort(0); // max_stack dos.writeShort(0); // max_locals dos.writeInt(bytecodes.length); // code_length dos.write(bytecodes); // code dos.writeShort(0); // exception_table_length List<Location> locations = withLineNumbers ? DebuggerUtilsEx.allLineLocations(method) : null; if (!ContainerUtil.isEmpty(locations)) { dos.writeShort(1); // attributes_count dos.writeShort(cw.newUTF8("LineNumberTable")); dos.writeInt(2 * locations.size() + 2); dos.writeShort(locations.size()); for (Location l : locations) { dos.writeShort((short)l.codeIndex()); dos.writeShort(l.lineNumber()); } } else { dos.writeShort(0); // attributes_count } }); }