[jboss-jira] [JBoss JIRA] Closed: (JASSIST-119) CtClass should have getField(String name, String desc)

Shigeru Chiba (JIRA) jira-events at lists.jboss.org
Thu Jul 8 07:04:47 EDT 2010


     [ https://jira.jboss.org/browse/JASSIST-119?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Shigeru Chiba closed JASSIST-119.
---------------------------------



> CtClass should have getField(String name, String desc)
> ------------------------------------------------------
>
>                 Key: JASSIST-119
>                 URL: https://jira.jboss.org/browse/JASSIST-119
>             Project: Javassist
>          Issue Type: Feature Request
>    Affects Versions: 3.12.0.GA
>            Reporter: Yu Kobayashi
>            Assignee: Shigeru Chiba
>             Fix For: 3.13.0.GA
>
>
> Java language does not allow to have same name fields in a class like this.
> class TestClass {
>     int a;
>     long a;
> }
> However, this is allowed in a Java class file, and actually some obfuscator using this.
> Therefore, CtClass and its subclass should have getField(String name, String desc).
> Please add these to CtClass.java and preserve original getField(String name).
>     public CtField getField(String name, String desc) throws NotFoundException {
>         throw new NotFoundException(name + " " + desc);
>     }
>     CtField getField2(String name, String desc) { return null; }
>     public CtField getDeclaredField(String name, String desc) throws NotFoundException {
>         throw new NotFoundException(name + " " + desc);
>     }
> Also please add this to CtClassType.java, and remove original getField, getField2, getDeclaredField, and getDeclaredField2.
>     public CtField getField(String name) throws NotFoundException {
>     	return getField(name, null);
>     }
>     public CtField getField(String name, String desc) throws NotFoundException {
>         CtField f = getField2(name, desc);
>         if (f == null)
>             throw new NotFoundException("field: " + name + " in " + getName());
>         else
>             return f;
>     }
>     CtField getField2(String name, String desc) {
>         CtField df = getDeclaredField2(name, desc);
>         if (df != null)
>             return df;
>         try {
>             CtClass[] ifs = getInterfaces();
>             int num = ifs.length;
>             for (int i = 0; i < num; ++i) {
>                 CtField f = ifs[i].getField2(name, desc);
>                 if (f != null)
>                     return f;
>             }
>             CtClass s = getSuperclass();
>             if (s != null)
>                 return s.getField2(name, desc);
>         }
>         catch (NotFoundException e) {}
>         return null;
>     }
>     public CtField getDeclaredField(String name) throws NotFoundException {
>     	return getDeclaredField(name, null);
>     }
>     
>     public CtField getDeclaredField(String name, String desc) throws NotFoundException {
>         CtField f = getDeclaredField2(name, desc);
>         if (f == null)
>             throw new NotFoundException("field: " + name + " in " + getName());
>         else
>             return f;
>     }
>     private CtField getDeclaredField2(String name, String desc) {
>         CtMember.Cache memCache = getMembers();
>         CtMember field = memCache.fieldHead();
>         CtMember tail = memCache.lastField();
>         while (field != tail) {
>             field = field.next();
>             if (field.getName().equals(name) && (desc == null || desc.equals(field.getSignature())))
>                 return (CtField)field;
>         }
>         return null;
>     }
> Sorry for these are not a diff file and copy and paste from my source files.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the jboss-jira mailing list