Details

    • Type: Bug
    • Status: New
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 11.0.3, 14
    • Fix Version/s: None
    • Component/s: tools
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      A DESCRIPTION OF THE PROBLEM :
      here is my code :

      public class test {
          Object ownName;
          public void test(String ownName) {
              this.ownName = ownName ;
          }
          public void aaa() {
              this.ownName = new Object();
              var a = new test() {
                  public void abc() {
                      System.out.println(ownName.hashCode());
                  }
              };
              a.abc();
              System.out.println(ownName.hashCode());
          }

          public static void main(String[] args) {
              new test().aaa();
          }
      }

      the inner no-name class (test$1) byte codes:
      Classfile /C:/Users/yuyang/IdeaProjects/javaTest/src/test$1.class
        Last modified 2019 size 580 bytes
        MD5 checksum 4f8be75560d6cad7eb66f36180ff0c70
        Compiled from "test.java"
      class test$1 extends test
        minor version: 0
        major version: 55
        flags: (0x0020) ACC_SUPER
        this_class: #7 // test$1
        super_class: #8 // test
        interfaces: 0, fields: 1, methods: 2, attributes: 4
      Constant pool:
         #1 = Fieldref #7.#22 // test$1.this$0:Ltest;
         #2 = Methodref #8.#23 // test."<init>":()V
         #3 = Fieldref #24.#25 // java/lang/System.out:Ljava/io/PrintStream;
         #4 = Fieldref #7.#26 // test$1.ownName:Ljava/lang/Object;
         #5 = Methodref #27.#28 // java/lang/Object.hashCode:()I
         #6 = Methodref #29.#30 // java/io/PrintStream.println:(I)V
         #7 = Class #31 // test$1
         #8 = Class #33 // test
         #9 = Utf8 this$0
        #10 = Utf8 Ltest;
        #11 = Utf8 <init>
        #12 = Utf8 (Ltest;)V
        #13 = Utf8 Code
        #14 = Utf8 LineNumberTable
        #15 = Utf8 abc
        #16 = Utf8 ()V
        #17 = Utf8 SourceFile
        #18 = Utf8 test.java
        #19 = Utf8 EnclosingMethod
        #20 = NameAndType #34:#16 // aaa:()V
        #21 = Utf8 NestHost
        #22 = NameAndType #9:#10 // this$0:Ltest;
        #23 = NameAndType #11:#16 // "<init>":()V
        #24 = Class #35 // java/lang/System
        #25 = NameAndType #36:#37 // out:Ljava/io/PrintStream;
        #26 = NameAndType #38:#39 // ownName:Ljava/lang/Object;
        #27 = Class #40 // java/lang/Object
        #28 = NameAndType #41:#42 // hashCode:()I
        #29 = Class #43 // java/io/PrintStream
        #30 = NameAndType #44:#45 // println:(I)V
        #31 = Utf8 test$1
        #32 = Utf8 InnerClasses
        #33 = Utf8 test
        #34 = Utf8 aaa
        #35 = Utf8 java/lang/System
        #36 = Utf8 out
        #37 = Utf8 Ljava/io/PrintStream;
        #38 = Utf8 ownName
        #39 = Utf8 Ljava/lang/Object;
        #40 = Utf8 java/lang/Object
        #41 = Utf8 hashCode
        #42 = Utf8 ()I
        #43 = Utf8 java/io/PrintStream
        #44 = Utf8 println
        #45 = Utf8 (I)V
      {
        final test this$0;
          descriptor: Ltest;
          flags: (0x1010) ACC_FINAL, ACC_SYNTHETIC

        test$1(test);
          descriptor: (Ltest;)V
          flags: (0x0000)
          Code:
            stack=2, locals=2, args_size=2
               0: aload_0
               1: aload_1
               2: putfield #1 // Field this$0:Ltest;
               5: aload_0
               6: invokespecial #2 // Method test."<init>":()V
               9: return
            LineNumberTable:
              line 8: 0

        public void abc();
          descriptor: ()V
          flags: (0x0001) ACC_PUBLIC
          Code:
            stack=2, locals=1, args_size=1
               0: getstatic #3 // Field java/lang/System.out:Ljava/io/PrintStream;
               3: aload_0
               4: getfield #4 // Field ownName:Ljava/lang/Object;
               7: invokevirtual #5 // Method java/lang/Object.hashCode:()I
              10: invokevirtual #6 // Method java/io/PrintStream.println:(I)V
              13: return
            LineNumberTable:
              line 10: 0
              line 11: 13
      }
      SourceFile: "test.java"
      EnclosingMethod: #8.#20 // test.aaa
      NestHost: class test
      InnerClasses:
        #7; // class test$1


      the issue is this , the test$1 class is inherit from test , very time the "new test$1 " create a new test$1 instance is also create the test instance , I cannot access the origin test instance `s field!!

      but also there is an anther problem , the field "this$0" should be the capture variable to access the field "ownName" , but the field is never used ,since the test$1 class inherit from test the field "this$0" looks like useless !!

      FREQUENCY : always

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: