Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 4341b39

Browse files
authored
Merge pull request #12 from launchdarkly/drichelson/ch3424/sdk-migration-to-2-2-3-failing-for-java-7
Add no-arg constructors for things we deserialize from json.
2 parents a72f4d0 + 8fcea43 commit 4341b39

File tree

5 files changed

+45
-22
lines changed

5 files changed

+45
-22
lines changed

src/main/java/com/launchdarkly/client/FeatureFlag.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ class FeatureFlag {
1616
private static final Type mapType = new TypeToken<Map<String, FeatureFlag>>() {
1717
}.getType();
1818

19-
private final String key;
20-
private final int version;
21-
private final boolean on;
22-
private final List<Prerequisite> prerequisites;
23-
private final String salt;
24-
private final List<Target> targets;
25-
private final List<Rule> rules;
26-
private final VariationOrRollout fallthrough;
27-
private final Integer offVariation; //optional
28-
private final List<JsonElement> variations;
29-
private final boolean deleted;
19+
private String key;
20+
private int version;
21+
private boolean on;
22+
private List<Prerequisite> prerequisites;
23+
private String salt;
24+
private List<Target> targets;
25+
private List<Rule> rules;
26+
private VariationOrRollout fallthrough;
27+
private Integer offVariation; //optional
28+
private List<JsonElement> variations;
29+
private boolean deleted;
3030

3131
static FeatureFlag fromJson(String json) {
3232
return LDConfig.gson.fromJson(json, FeatureFlag.class);
@@ -36,6 +36,9 @@ static Map<String, FeatureFlag> fromJsonMap(String json) {
3636
return LDConfig.gson.fromJson(json, mapType);
3737
}
3838

39+
// We need this so Gson doesn't complain in certain java environments that restrict unsafe allocation
40+
FeatureFlag() {}
41+
3942
FeatureFlag(String key, int version, boolean on, List<Prerequisite> prerequisites, String salt, List<Target> targets, List<Rule> rules, VariationOrRollout fallthrough, Integer offVariation, List<JsonElement> variations, boolean deleted) {
4043
this.key = key;
4144
this.version = version;

src/main/java/com/launchdarkly/client/Prerequisite.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.launchdarkly.client;
22

33
class Prerequisite {
4-
private final String key;
5-
private final int variation;
4+
private String key;
5+
private int variation;
6+
7+
// We need this so Gson doesn't complain in certain java environments that restrict unsafe allocation
8+
Prerequisite() {}
69

710
Prerequisite(String key, int variation) {
811
this.key = key;

src/main/java/com/launchdarkly/client/Rule.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
* Invariant: one of the variation or rollout must be non-nil.
99
*/
1010
class Rule extends VariationOrRollout {
11-
private final List<Clause> clauses;
11+
private List<Clause> clauses;
12+
13+
// We need this so Gson doesn't complain in certain java environments that restrict unsafe allocation
14+
Rule() {
15+
super();
16+
}
1217

1318
Rule(List<Clause> clauses, Integer variation, Rollout rollout) {
1419
super(variation, rollout);

src/main/java/com/launchdarkly/client/Target.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
import java.util.List;
44

55
class Target {
6-
private final List<String> values;
7-
private final int variation;
6+
private List<String> values;
7+
private int variation;
8+
9+
// We need this so Gson doesn't complain in certain java environments that restrict unsafe allocation
10+
Target() {}
811

912
Target(List<String> values, int variation) {
1013
this.values = values;

src/main/java/com/launchdarkly/client/VariationOrRollout.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
class VariationOrRollout {
1414
private static final float long_scale = (float) 0xFFFFFFFFFFFFFFFL;
1515

16-
private final Integer variation;
17-
private final Rollout rollout;
16+
private Integer variation;
17+
private Rollout rollout;
18+
19+
// We need this so Gson doesn't complain in certain java environments that restrict unsafe allocation
20+
VariationOrRollout() {}
1821

1922
VariationOrRollout(Integer variation, Rollout rollout) {
2023
this.variation = variation;
@@ -56,8 +59,11 @@ private float bucketUser(LDUser user, String key, String attr, String salt) {
5659
}
5760

5861
static class Rollout {
59-
private final List<WeightedVariation> variations;
60-
private final String bucketBy;
62+
private List<WeightedVariation> variations;
63+
private String bucketBy;
64+
65+
// We need this so Gson doesn't complain in certain java environments that restrict unsafe allocation
66+
Rollout() {}
6167

6268
Rollout(List<WeightedVariation> variations, String bucketBy) {
6369
this.variations = variations;
@@ -66,8 +72,11 @@ static class Rollout {
6672
}
6773

6874
static class WeightedVariation {
69-
private final int variation;
70-
private final int weight;
75+
private int variation;
76+
private int weight;
77+
78+
// We need this so Gson doesn't complain in certain java environments that restrict unsafe allocation
79+
WeightedVariation() {}
7180

7281
WeightedVariation(int variation, int weight) {
7382
this.variation = variation;

0 commit comments

Comments
 (0)