I've similar issues with the analyze. There are unused imports in the
source code (lazy devs) which aren't seen by the analyzer. Haven't looked
into the byte code, but guess it's the same issue as here.

/Anders

On Thu, Nov 26, 2015 at 9:25 AM, Kristian Rosenvold <
kristian.rosenv...@gmail.com> wrote:

> What I still dont understand is;
>
> the string might be inlined, but the "import" still seems to be
> visible in the bytecode. Shouldn't dependency:analyze consider this a
> "usage" ?
>
> Kristian
>
>
> 2015-11-25 10:31 GMT+01:00 Stephen Connolly <
> stephen.alan.conno...@gmail.com>:
> > Well here's a how do you do...
> >
> > If I compile BarMain.java with foo/Test2.java using a plain =42, I get:
> >
> > public class BarMain {
> >
> >   public BarMain();
> >
> >     Code:
> >
> >        0: aload_0
> >
> >        1: invokespecial #1                  // Method
> > java/lang/Object."<init>":()V
> >
> >        4: return
> >
> >
> >   public static void main(java.lang.String[]);
> >
> >     Code:
> >
> >        0: getstatic     #2                  // Field
> > java/lang/System.out:Ljava/io/PrintStream;
> >
> >        3: ldc           #4                  // String AZ 42
> >
> >        5: invokevirtual #5                  // Method
> > java/io/PrintStream.println:(Ljava/lang/String;)V
> >
> >        8: return
> >
> > }
> >
> >
> > If I compile BarMain.java with foo/Test2.java using the prevent inlining
> =
> > null!=null?0:42 I get:
> >
> > public class BarMain {
> >
> >   public BarMain();
> >
> >     Code:
> >
> >        0: aload_0
> >
> >        1: invokespecial #1                  // Method
> > java/lang/Object."<init>":()V
> >
> >        4: return
> >
> >
> >   public static void main(java.lang.String[]);
> >
> >     Code:
> >
> >        0: getstatic     #2                  // Field
> > java/lang/System.out:Ljava/io/PrintStream;
> >
> >        3: new           #3                  // class
> java/lang/StringBuilder
> >
> >        6: dup
> >
> >        7: invokespecial #4                  // Method
> > java/lang/StringBuilder."<init>":()V
> >
> >       10: ldc           #5                  // String AZ
> >
> >       12: invokevirtual #6                  // Method
> >
> java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
> >
> >       15: getstatic     #7                  // Field foo/Test2.AZAZ:I
> >
> >       18: invokevirtual #8                  // Method
> > java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
> >
> >       21: invokevirtual #9                  // Method
> > java/lang/StringBuilder.toString:()Ljava/lang/String;
> >
> >       24: invokevirtual #10                 // Method
> > java/io/PrintStream.println:(Ljava/lang/String;)V
> >
> >       27: return
> >
> > }
> >
> >
> > So what I see there is that in the first case javac has inlined the
> > constant and converted it to a string... in the second case it is
> > referencing the field directly
> >
> >
> >
> > On 25 November 2015 at 08:53, Kristian Rosenvold <
> > kristian.rosenv...@gmail.com> wrote:
> >
> >> Let me be more precise here; the dependency:analyze seems to miss a
> >> whole group of references to static fields. Both static imports and
> >> references to fields. In my code sample, I can do the following:
> >>
> >> javap -v bar/BarMain.class
> >>
> >> Classfile bar/BarMain.class
> >>   Last modified 25.nov.2015; size 583 bytes
> >>   MD5 checksum 02168be555cf779b31a4790f97b202a7
> >>   Compiled from "BarMain.java"
> >> public class bar.BarMain
> >>   minor version: 0
> >>   major version: 49
> >>   flags: ACC_PUBLIC, ACC_SUPER
> >> Constant pool:
> >>    #1 = Class              #23            // foo/Main
> >>    #2 = Methodref          #9.#24         //
> java/lang/Object."<init>":()V
> >>    #3 = Fieldref           #25.#26        //
> >> java/lang/System.out:Ljava/io/PrintStream;
> >>    #4 = String             #27            // SC compile
> >>    #5 = Methodref          #28.#29        //
> >> java/io/PrintStream.println:(Ljava/lang/String;)V
> >>    #6 = Class              #30            // foo/Test2
> >>    #7 = String             #31            // AZ 42
> >>    #8 = Class              #32            // bar/BarMain
> >>    #9 = Class              #33            // java/lang/Object
> >>   #10 = Utf8               <init>
> >>   #11 = Utf8               ()V
> >>   #12 = Utf8               Code
> >>   #13 = Utf8               LineNumberTable
> >>   #14 = Utf8               LocalVariableTable
> >>   #15 = Utf8               this
> >>   #16 = Utf8               Lbar/BarMain;
> >>   #17 = Utf8               main
> >>   #18 = Utf8               ([Ljava/lang/String;)V
> >>   #19 = Utf8               args
> >>   #20 = Utf8               [Ljava/lang/String;
> >>   #21 = Utf8               SourceFile
> >>   #22 = Utf8               BarMain.java
> >>   #23 = Utf8               foo/Main
> >>   #24 = NameAndType        #10:#11        // "<init>":()V
> >>   #25 = Class              #34            // java/lang/System
> >>   #26 = NameAndType        #35:#36        // out:Ljava/io/PrintStream;
> >>   #27 = Utf8               SC compile
> >>   #28 = Class              #37            // java/io/PrintStream
> >>   #29 = NameAndType        #38:#39        //
> println:(Ljava/lang/String;)V
> >>   #30 = Utf8               foo/Test2
> >>   #31 = Utf8               AZ 42
> >>   #32 = Utf8               bar/BarMain
> >>   #33 = Utf8               java/lang/Object
> >>   #34 = Utf8               java/lang/System
> >>   #35 = Utf8               out
> >>   #36 = Utf8               Ljava/io/PrintStream;
> >>   #37 = Utf8               java/io/PrintStream
> >>   #38 = Utf8               println
> >>   #39 = Utf8               (Ljava/lang/String;)V
> >> {
> >>   public bar.BarMain();
> >>     descriptor: ()V
> >>     flags: ACC_PUBLIC
> >>     Code:
> >>       stack=1, locals=1, args_size=1
> >>          0: aload_0
> >>          1: invokespecial #2                  // Method
> >> java/lang/Object."<init>":()V
> >>          4: return
> >>       LineNumberTable:
> >>         line 25: 0
> >>       LocalVariableTable:
> >>         Start  Length  Slot  Name   Signature
> >>             0       5     0  this   Lbar/BarMain;
> >>
> >>   public static void main(java.lang.String[]);
> >>     descriptor: ([Ljava/lang/String;)V
> >>     flags: ACC_PUBLIC, ACC_STATIC
> >>     Code:
> >>       stack=2, locals=1, args_size=1
> >>          0: getstatic     #3                  // Field
> >> java/lang/System.out:Ljava/io/PrintStream;
> >>          3: ldc           #4                  // String SC compile
> >>          5: invokevirtual #5                  // Method
> >> java/io/PrintStream.println:(Ljava/lang/String;)V
> >>          8: getstatic     #3                  // Field
> >> java/lang/System.out:Ljava/io/PrintStream;
> >>         11: ldc           #7                  // String AZ 42
> >>         13: invokevirtual #5                  // Method
> >> java/io/PrintStream.println:(Ljava/lang/String;)V
> >>         16: return
> >>       LineNumberTable:
> >>         line 28: 0
> >>         line 29: 8
> >>         line 30: 16
> >>       LocalVariableTable:
> >>         Start  Length  Slot  Name   Signature
> >>             0      17     0  args   [Ljava/lang/String;
> >> }
> >> SourceFile: "BarMain.java"
> >>
> >> As we can see the "import" class "foo/Test" is item #6/#30 and
> >> referenced in the constant pool for the BarMain class. The dependency
> >> analyzer does not seem to catch this. I'm a bit of a n00b in this
> >> regard, anyone have any tips on how to do this ?
> >>
> >> Kristian
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org
> >> For additional commands, e-mail: dev-h...@maven.apache.org
> >>
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org
> For additional commands, e-mail: dev-h...@maven.apache.org
>
>

Reply via email to