Skip to content

Missing values for non-static final fields #379

@rankinc

Description

@rankinc

Hi,

I have been trying to update a (very!) old code-base from FastClasspathScanner 2.18.1 to ClassGraph 4.8.52. This code must be able to scan Kotlin as well as Java classes, and while I have replicated most of the functionality, I am still struggling to persuade ClassGraph to handle this:

class HasJvmField {
    @JvmField
    val stringValue = "Hello World"
}

The problem is that ClassGraph doesn't realise that this field has an initialier, whereas FastClasspathScanner did. The Kotlin compiler generates the following byte-code for this case:

  public final java.lang.String stringValue;
    descriptor: Ljava/lang/String;
    flags: ACC_PUBLIC, ACC_FINAL
    ConstantValue: String Hello World
    RuntimeInvisibleAnnotations:
      0: #9()
      1: #10()

   #9 = Utf8               Lkotlin/jvm/JvmField;
  #10 = Utf8               Lorg/jetbrains/annotations/NotNull;

I suspect this is because stringValue is not a static field and so enabling

.enableStaticFinalFieldConstantInitializerValues()

does not help me here.

Is there a workaround for this please?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions