Skip to content

Commit 913096c

Browse files
committed
Use default value when accessing un-initialized Property
Accessing an uninitialized Property is illegal, resulting in errors or warnings when CCUDGP is applied with no value set for 'server'. This is fixed by providing a default value to use in the case of uninitialized Property. Fixes gradle/common-custom-user-data-gradle-plugin#378
1 parent 40efdaa commit 913096c

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

Diff for: develocity-gradle-plugin-adapters/src/compatibilityApi/java/com/gradle/develocity/agent/gradle/adapters/internal/ReflectionProperty.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,14 @@ public static <T> ReflectionProperty<T> forGetterAndSetter(Object obj, String ge
5757
}
5858

5959
public static <T> ReflectionProperty<T> forProperty(Object obj, String propertyName) {
60+
return forProperty(obj, propertyName, null);
61+
}
62+
63+
public static <T> ReflectionProperty<T> forProperty(Object obj, String propertyName, T defaultValue) {
6064
return new ReflectionProperty<>(
6165
() -> {
6266
Property<T> prop = (Property<T>) invokeMethod(obj, propertyName);
63-
return prop.get();
67+
return prop.getOrElse(defaultValue);
6468
},
6569
value -> {
6670
Property<T> prop = (Property<T>) invokeMethod(obj, propertyName);

Diff for: develocity-gradle-plugin-adapters/src/develocityCompatibility/java/com/gradle/develocity/agent/gradle/adapters/develocity/BuildScanCaptureConfigurationAdapter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public static BuildScanCaptureAdapter forBuildScanExtension(Object buildScan) {
3737
@VisibleForTesting
3838
static @NotNull ReflectingBuildScanCaptureAdapter forCaptureConfiguration(Object capture) {
3939
return new ReflectingBuildScanCaptureAdapter(
40-
ReflectionProperty.forProperty(capture, "getFileFingerprints"),
41-
ReflectionProperty.forProperty(capture, "getBuildLogging"),
42-
ReflectionProperty.forProperty(capture, "getTestLogging")
40+
ReflectionProperty.forProperty(capture, "getFileFingerprints", true),
41+
ReflectionProperty.forProperty(capture, "getBuildLogging", true),
42+
ReflectionProperty.forProperty(capture, "getTestLogging", true)
4343
);
4444
}
4545
}

Diff for: develocity-gradle-plugin-adapters/src/develocityCompatibility/java/com/gradle/develocity/agent/gradle/adapters/develocity/BuildScanConfigurationAdapter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected ReflectionProperty<String> getTermsOfUseAgreeProperty() {
5454

5555
@Override
5656
protected ReflectionProperty<Boolean> getUploadInBackgroundProperty() {
57-
return ReflectionProperty.forProperty(buildScanExtension, "getUploadInBackground");
57+
return ReflectionProperty.forProperty(buildScanExtension, "getUploadInBackground", true);
5858
}
5959

6060
@Nullable

Diff for: develocity-gradle-plugin-adapters/src/develocityCompatibility/java/com/gradle/develocity/agent/gradle/adapters/develocity/DevelocityConfigurationAdapter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected ReflectionProperty<String> getProjectIdProperty() {
5555

5656
@Override
5757
protected ReflectionProperty<Boolean> getAllowUntrustedServerProperty() {
58-
return ReflectionProperty.forProperty(extension, "getAllowUntrustedServer");
58+
return ReflectionProperty.forProperty(extension, "getAllowUntrustedServer", true);
5959
}
6060

6161
@Override

0 commit comments

Comments
 (0)