Skip to content

Commit

Permalink
JDK8 compatibility for non-test classes (#227)
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Disselkoen <cdiss@amazon.com>
  • Loading branch information
cdisselkoen authored Oct 2, 2024
1 parent 0da1ffe commit 1a577d4
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 14 deletions.
10 changes: 10 additions & 0 deletions CedarJava/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ test {
}
}

compileTestJava {
sourceCompatibility = "17"
targetCompatibility = "17"
}

compileJava {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}

tasks.named('build') {
dependsOn('uberJar')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean equals(final Object lhs) {
return false;
}

final var sl = (SourceLocation) lhs;
final SourceLocation sl = (SourceLocation) lhs;
return this.start == sl.start && this.end == sl.end;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ public String toJson() throws InternalException, NullPointerException {
}

public static Policy fromJson(String policyId, String policyJson) throws InternalException, NullPointerException {
var policyText = fromJsonJni(policyJson);
String policyText = fromJsonJni(policyJson);
return new Policy(policyText, policyId);
}

public static Policy parseStaticPolicy(String policyStr) throws InternalException, NullPointerException {
var policyText = parsePolicyJni(policyStr);
String policyText = parsePolicyJni(policyStr);
return new Policy(policyText, null);
}

public static Policy parsePolicyTemplate(String templateStr) throws InternalException, NullPointerException {
var templateText = parsePolicyTemplateJni(templateStr);
String templateText = parsePolicyTemplateJni(templateStr);
return new Policy(templateText, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.cedarpolicy.value.EntityUID;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Optional;

/** Represent JSON format of Entity Unique Identifier. */
public class JsonEUID {
Expand All @@ -36,7 +37,7 @@ public class JsonEUID {
@Override
public String toString() {
try {
var mapper = new ObjectMapper();
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(this);
} catch (JsonProcessingException e) {
throw new RuntimeException("Internal invariant violated, json encoding failed: " + e.toString());
Expand All @@ -55,9 +56,9 @@ public JsonEUID(String type, String id) {

@SuppressFBWarnings("CT_CONSTRUCTOR_THROW")
public JsonEUID(String src) throws InvalidEUIDException {
var o = EntityUID.parse(src);
Optional<EntityUID> o = EntityUID.parse(src);
if (o.isPresent()) {
var x = o.get().asJson();
JsonEUID x = o.get().asJson();
this.type = x.type;
this.id = x.id;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.Optional;

/** Deserialize Json to Value. This is mostly an implementation detail, but you may need to modify it if you extend the
* `Value` class. */
Expand Down Expand Up @@ -95,12 +96,12 @@ public Value deserialize(JsonParser parser, DeserializationContext context) thro
numFields++;
}
if (numFields == 2) {
var id = new EntityIdentifier(val.get("id").textValue());
var type = EntityTypeName.parse(val.get("type").textValue());
EntityIdentifier id = new EntityIdentifier(val.get("id").textValue());
Optional<EntityTypeName> type = EntityTypeName.parse(val.get("type").textValue());
if (type.isPresent()) {
return new EntityUID(type.get(), id);
} else {
var msg = "Invalid Entity Type" + val.get("type").textValue();
String msg = "Invalid Entity Type" + val.get("type").textValue();
throw new InvalidValueDeserializationException(parser, msg, node.asToken(), Map.class);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public boolean equals(Object o) {
return false;
} else {
try {
var rhs = (EntityIdentifier) o;
EntityIdentifier rhs = (EntityIdentifier) o;
return this.id.equals(rhs.id);
} catch (ClassCastException e) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public boolean equals(Object rhs) {
return true;
}
try {
var rhsTypename = (EntityTypeName) rhs;
EntityTypeName rhsTypename = (EntityTypeName) rhs;
return basename.equals(rhsTypename.basename) && namespace.equals(rhsTypename.namespace);
} catch (ClassCastException e) {
return false;
Expand Down
3 changes: 1 addition & 2 deletions CedarJava/src/main/java/com/cedarpolicy/value/EntityUID.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public boolean equals(Object o) {
return true;
} else {
try {
var rhs = (EntityUID) o;
EntityUID rhs = (EntityUID) o;
return this.type.equals(rhs.type) && this.id.equals(rhs.id);
} catch (ClassCastException e) {
return false;
Expand Down Expand Up @@ -122,4 +122,3 @@ public static Optional<EntityUID> parseFromJson(JsonEUID euid) {
private static native String getEUIDRepr(EntityTypeName type, EntityIdentifier id);

}

0 comments on commit 1a577d4

Please sign in to comment.