Missing type information (not seen in visitor)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Missing type information (not seen in visitor)

Showalter, Jim
We have two classes like this:

package com.intuit.foo;

public class Foo {
}

public class FooHolder {
               private List<Foo> foos = new ArrayList<>();
}

After visiting both classes and dumping out the info, I see this:

com/intuit/foo/Foo:
  class, lines 0 to ~2, deletable, public

com/intuit/foo/Foos:
  class, lines 0 to ~2, not-deletable, public
  type references
    <none>
  field declarations
    com/intuit/obill/v1/quote/response/Quote:chargeDetails:Ljava/util/List;

Note that the type Foo is not seen in when visiting the Foos. Because there are no other references to Foo anywhere, this results in a false-positive delete of Foo.java.

I collect all of the referred-to types in the visitor like this:

               @Override
               public void visitConstantClass(final ConstantClass obj) {
                              String className = JavaUtils.dotsToSlashes(javaClass().getConstantPool().getConstant(obj.getNameIndex()).toString().replace("\")", "").replaceAll("^.*\"", ""));
                              if (ignore(className)) {
                                             return;
                              }
                              type().addTypeReference(className);
               }

What am I doing wrong?

Jim Showalter
Programmer
Intuit, 2003H-265Z
Garcia Avenue
Mountain View, CA 94043
(408) 353-4954 [home]
(408) 204-1661 [personal cell]
(669) 271-2257 [work cell]

Reply | Threaded
Open this post in threaded view
|

Re: Missing type information (not seen in visitor)

garydgregory
Which Commons component are you using?

Gary

On Sep 25, 2017 17:05, "Showalter, Jim" <[hidden email]> wrote:

> We have two classes like this:
>
> package com.intuit.foo;
>
> public class Foo {
> }
>
> public class FooHolder {
>                private List<Foo> foos = new ArrayList<>();
> }
>
> After visiting both classes and dumping out the info, I see this:
>
> com/intuit/foo/Foo:
>   class, lines 0 to ~2, deletable, public
>
> com/intuit/foo/Foos:
>   class, lines 0 to ~2, not-deletable, public
>   type references
>     <none>
>   field declarations
>     com/intuit/obill/v1/quote/response/Quote:chargeDetails:
> Ljava/util/List;
>
> Note that the type Foo is not seen in when visiting the Foos. Because
> there are no other references to Foo anywhere, this results in a
> false-positive delete of Foo.java.
>
> I collect all of the referred-to types in the visitor like this:
>
>                @Override
>                public void visitConstantClass(final ConstantClass obj) {
>                               String className = JavaUtils.dotsToSlashes(
> javaClass().getConstantPool().getConstant(obj.getNameIndex()).toString().replace("\")",
> "").replaceAll("^.*\"", ""));
>                               if (ignore(className)) {
>                                              return;
>                               }
>                               type().addTypeReference(className);
>                }
>
> What am I doing wrong?
>
> Jim Showalter
> Programmer
> Intuit, 2003H-265Z
> Garcia Avenue
> Mountain View, CA 94043
> (408) 353-4954 [home]
> (408) 204-1661 [personal cell]
> (669) 271-2257 [work cell]
>
>
Reply | Threaded
Open this post in threaded view
|

RE: Missing type information (not seen in visitor)

Showalter, Jim
org.apache.bcel

-----Original Message-----
From: Gary Gregory [mailto:[hidden email]]
Sent: Monday, September 25, 2017 6:15 PM
To: Commons Users List <[hidden email]>
Subject: Re: Missing type information (not seen in visitor)

Which Commons component are you using?

Gary

On Sep 25, 2017 17:05, "Showalter, Jim" <[hidden email]> wrote:

> We have two classes like this:
>
> package com.intuit.foo;
>
> public class Foo {
> }
>
> public class FooHolder {
>                private List<Foo> foos = new ArrayList<>(); }
>
> After visiting both classes and dumping out the info, I see this:
>
> com/intuit/foo/Foo:
>   class, lines 0 to ~2, deletable, public
>
> com/intuit/foo/Foos:
>   class, lines 0 to ~2, not-deletable, public
>   type references
>     <none>
>   field declarations
>     com/intuit/obill/v1/quote/response/Quote:chargeDetails:
> Ljava/util/List;
>
> Note that the type Foo is not seen in when visiting the Foos. Because
> there are no other references to Foo anywhere, this results in a
> false-positive delete of Foo.java.
>
> I collect all of the referred-to types in the visitor like this:
>
>                @Override
>                public void visitConstantClass(final ConstantClass obj) {
>                               String className =
> JavaUtils.dotsToSlashes(
> javaClass().getConstantPool().getConstant(obj.getNameIndex()).toString
> ().replace("\")",
> "").replaceAll("^.*\"", ""));
>                               if (ignore(className)) {
>                                              return;
>                               }
>                               type().addTypeReference(className);
>                }
>
> What am I doing wrong?
>
> Jim Showalter
> Programmer
> Intuit, 2003H-265Z
> Garcia Avenue
> Mountain View, CA 94043
> (408) 353-4954 [home]
> (408) 204-1661 [personal cell]
> (669) 271-2257 [work cell]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Missing type information (not seen in visitor)

Guang Chao
In reply to this post by Showalter, Jim
On Tue, Sep 26, 2017 at 7:05 AM, Showalter, Jim <[hidden email]>
wrote:

> We have two classes like this:
>
> package com.intuit.foo;
>
> public class Foo {
> }
>
> public class FooHolder {
>                private List<Foo> foos = new ArrayList<>();
> }
>
> After visiting both classes and dumping out the info, I see this:
>
> com/intuit/foo/Foo:
>   class, lines 0 to ~2, deletable, public
>
> com/intuit/foo/Foos:
>   class, lines 0 to ~2, not-deletable, public
>   type references
>     <none>
>   field declarations
>     com/intuit/obill/v1/quote/response/Quote:chargeDetails:
> Ljava/util/List;
>
> Note that the type Foo is not seen in when visiting the Foos. Because
> there are no other references to Foo anywhere, this results in a
> false-positive delete of Foo.java.
>

I think that is expected for Generics if I am not mistaken.  The Foo in
List<Foo> is just for compile time.  On runtime, it just knows that it is a
List, and do not know it is a list of Foo.


>
> I collect all of the referred-to types in the visitor like this:
>
>                @Override
>                public void visitConstantClass(final ConstantClass obj) {
>                               String className = JavaUtils.dotsToSlashes(
> javaClass().getConstantPool().getConstant(obj.getNameIndex()).toString().replace("\")",
> "").replaceAll("^.*\"", ""));
>                               if (ignore(className)) {
>                                              return;
>                               }
>                               type().addTypeReference(className);
>                }
>
> What am I doing wrong?
>
> Jim Showalter
> Programmer
> Intuit, 2003H-265Z
> Garcia Avenue
> Mountain View, CA 94043
> (408) 353-4954 [home]
> (408) 204-1661 [personal cell]
> (669) 271-2257 [work cell]
>
>


--
Guang <http://grails.asia/how-to-add-element-to-string-array-in-java/>