Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No handling for non-class annotations #347

Open
SilverAndro opened this issue Mar 9, 2024 · 0 comments
Open

No handling for non-class annotations #347

SilverAndro opened this issue Mar 9, 2024 · 0 comments
Labels
bug Something isn't working Priority: Low Low priority Subsystem: Writing Anything concerning how expressions are written

Comments

@SilverAndro
Copy link

Per https://docs.oracle.com/javase/specs/jvms/se21/html/jvms-4.html#jvms-4.7.16:

type_index
The value of the type_index item must be a valid index into the constant_pool table. The constant_pool entry at that index must be a CONSTANT_Utf8_info structure (§4.4.7) representing a field descriptor (§4.3.2). The field descriptor denotes the type of the annotation represented by this annotation structure.

I don't believe this is possible from java, however it is possible to create and load a class that uses arrays or primitives as an annotation type.

javap manages to handle this by expanding it to the primitive type:

javap output
Classfile PrimitiveAnnotations.class
  Last modified Mar 9, 2024; size 391 bytes
  SHA-256 checksum 13cd127eecea39c43cc4c134ff1370934e77a071f2b768d2184c0f264dd04f97
public class PrimitiveAnnotations
  minor version: 0
  major version: 52
  flags: (0x0001) ACC_PUBLIC
  this_class: #2                          // PrimitiveAnnotations
  super_class: #4                         // java/lang/Object
  interfaces: 0, fields: 0, methods: 1, attributes: 1
Constant pool:
   #1 = Utf8               PrimitiveAnnotations
   #2 = Class              #1             // PrimitiveAnnotations
   #3 = Utf8               java/lang/Object
   #4 = Class              #3             // java/lang/Object
   #5 = Utf8               Z
   #6 = Utf8               [I
   #7 = Utf8               C
   #8 = Utf8               s
   #9 = Integer            3
  #10 = Utf8               [[D
  #11 = Integer            -1
  #12 = Utf8               main
  #13 = Utf8               ([Ljava/lang/String;)V
  #14 = Utf8               java/lang/System
  #15 = Class              #14            // java/lang/System
  #16 = Utf8               out
  #17 = Utf8               Ljava/io/PrintStream;
  #18 = NameAndType        #16:#17        // out:Ljava/io/PrintStream;
  #19 = Fieldref           #15.#18        // java/lang/System.out:Ljava/io/PrintStream;
  #20 = Utf8               Hello, world!
  #21 = String             #20            // Hello, world!
  #22 = Utf8               java/io/PrintStream
  #23 = Class              #22            // java/io/PrintStream
  #24 = Utf8               println
  #25 = Utf8               (Ljava/lang/String;)V
  #26 = NameAndType        #24:#25        // println:(Ljava/lang/String;)V
  #27 = Methodref          #23.#26        // java/io/PrintStream.println:(Ljava/lang/String;)V
  #28 = Utf8               Code
  #29 = Utf8               RuntimeVisibleAnnotations
{
  public static void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: (0x0009) ACC_PUBLIC, ACC_STATIC
    Code:
      stack=2, locals=1, args_size=1
         0: getstatic     #19                 // Field java/lang/System.out:Ljava/io/PrintStream;
         3: ldc           #21                 // String Hello, world!
         5: invokevirtual #27                 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
         8: return
}
RuntimeVisibleAnnotations:
  0: #5()
    boolean
  1: #6()
    int[]
  2: #7(#8=I#9)
    char(
      s=3
    )
  3: #10(#8=I#11)
    double[][](
      s=-1
    )

However vineflower currently emits the descriptor directly without comment, likely causing issues or confusion in obfuscated environments:

vineflower output (1.9.3)
@Z
@I
@C(
   s = 3
)
@D(
   s = -1
)
public class PrimitiveAnnotations {
   public static void main(String[] var0) {
      System.out.println("Hello, world!");
   }
}

PrimitiveAnnotations.zip

@jaskarth jaskarth added Subsystem: Writing Anything concerning how expressions are written Priority: Low Low priority bug Something isn't working labels Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Priority: Low Low priority Subsystem: Writing Anything concerning how expressions are written
Projects
None yet
Development

No branches or pull requests

2 participants