Skip to content

Commit

Permalink
Refine KotlinDetector for compliance with ConstantFieldFeature
Browse files Browse the repository at this point in the history
After this commit, KotlinDetector#kotlinPresent is
computed at build time.

See spring-projectsgh-28624
  • Loading branch information
sdeleuze committed Jun 27, 2022
1 parent 798dd4f commit f8508c8
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,6 +35,9 @@ public abstract class KotlinDetector {
@Nullable
private static final Class<? extends Annotation> kotlinMetadata;

// For ConstantFieldFeature compliance, otherwise could be deduced from kotlinMetadata
private static final boolean kotlinPresent;

private static final boolean kotlinReflectPresent;

static {
Expand All @@ -48,6 +51,7 @@ public abstract class KotlinDetector {
metadata = null;
}
kotlinMetadata = (Class<? extends Annotation>) metadata;
kotlinPresent = (kotlinMetadata != null);
kotlinReflectPresent = ClassUtils.isPresent("kotlin.reflect.full.KClasses", classLoader);
}

Expand All @@ -56,7 +60,7 @@ public abstract class KotlinDetector {
* Determine whether Kotlin is present in general.
*/
public static boolean isKotlinPresent() {
return (kotlinMetadata != null);
return kotlinPresent;
}

/**
Expand Down

0 comments on commit f8508c8

Please sign in to comment.