Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

40
LINES

< > BotCompany Repo | #1033513 // bcelFixDuplicateInnerClassesECJBug

JavaX fragment (include) [tags: use-pretranspiled]

Uses 1311K of libraries. Click here for Pure Java version (5763L/32K).

import org.apache.bcel.classfile.InnerClasses;
import org.apache.bcel.classfile.InnerClass;
import org.apache.bcel.generic.ClassGen;

static File bcelFixDuplicateInnerClassesECJBug(File/S jar, S classFileInJar) {
  
  //extractProjectForLocalCompilation(#1033411, userDir("dev/1033411"))
  
  File file = jar;
  S path = classFileInJar;
  JavaClass c = bcel_classInZip(file, path);
  //dm_showText(pnlToString(sortedAlphaNumIC(map(c.getAttributes(), a -> a.getNameIndex() + ": " + a)));
  var ic = firstThat(c.getAttributes(), a -> eq(a.getName(), "InnerClasses"));
  print(ic := className(ic));
  cast ic to InnerClasses;
  
  InnerClass[] icList = ic.getInnerClasses();
  //dm_showText(lines(icList));
  var dup = duplicates(allToString(icList));
  printMultiSet(dup);
  if (nempty(dup)) {
    print("DUPLICATES!!");
    Cl<InnerClass> filtered = values(mapToKeys toString(icList));
    
    //ClassGen cg = new ClassGen(c);
    /*Attribute[] attributesCG = cg.getAttributes();
    var ic2 = firstThat(attributesCG, a -> eq(a.getName(), "InnerClasses"));
    printVars(ic2 := className(ic), same := (ic == ic2));
    cast ic2 to InnerClasses;*/
    
    ic.setInnerClasses(toArrayOfType InnerClass(filtered));
    c = new ClassGen(c).getJavaClass(); // rotate!?
    printFileInfo(bcelSave(c, newFileInSameDir(file, path)));
    File newJar = appendToBaseName(jar, ".bytecodefix");
    replaceFileZip2Zip(jar, newJar, path, c.getBytes());
    printFileInfo(newJar);
    ret newJar;
  }
  null;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033513
Snippet name: bcelFixDuplicateInnerClassesECJBug
Eternal ID of this version: #1033513/8
Text MD5: acdaa9b62a2cf47e01132548c2355f4a
Transpilation MD5: 00f159f9f40f01953eed2824898fed3d
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-29 09:27:20
Source code size: 1535 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 398 / 475
Version history: 7 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)