Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: start turning on werror for code. #32

Merged
merged 1 commit into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,34 @@ project.ext.externalDependency = [
apply plugin: 'com.diffplug.spotless'
apply plugin: 'org.shipkit.shipkit-auto-version'

// TODO expand this to all projects and then delete this allow list. This list is letting us fix errors over time rather
// than in one big change.
def wErrorProjects = [
project(':core-models'),
// project(':dao-api'),
// project(':dao-api-impl'),
// project(':restli-resources'),
project(':testing'),
project(':validators')
]

allprojects {
group = "com.linkedin.datahub-gma"

apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'checkstyle'

gradle.projectsEvaluated {
if (wErrorProjects.contains(project)) {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:all" << "-Werror" <<
"-Xlint:-deprecation" << // TODO
"-Xlint:-processing" << // TODO we have annotations like @Nonnull that need a processor
"-Xlint:-serial" // I don't think we care about having custom Exception subclasses be serializable...
}
}
}
}

if (!project.hasProperty('disableShipkit')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,7 @@ public <T> T getAs(int index, Class<T> clazz) {
} else if (Long.TYPE.equals(clazz) || Long.class.equals(clazz)) {
result = Long.valueOf(value);
} else if (Enum.class.isAssignableFrom(clazz)) {
final Class<? extends Enum> enumClazz = clazz.asSubclass(Enum.class);
@SuppressWarnings("unchecked")
Enum<?> enumValue = Enum.valueOf(enumClazz, value);
result = enumValue;
result = getEnumValue(clazz, value);
} else if (DataTemplateUtil.hasCoercer(clazz)) {
result = DataTemplateUtil.coerceOutput(value, clazz);
} else {
Expand All @@ -169,6 +166,15 @@ public <T> T getAs(int index, Class<T> clazz) {
return rv;
}

/**
* Helper method to capture E.
*/
private <E extends Enum<E>> Enum<E> getEnumValue(Class<?> clazz, String value) {
@SuppressWarnings("unchecked")
final Class<E> enumClazz = (Class<E>) clazz.asSubclass(Enum.class);
return Enum.valueOf(enumClazz, value);
}

public int size() {
return _tuple.size();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public Object coerceInput(T object) throws ClassCastException {
return object.toString();
}

@SuppressWarnings("unchecked")
public T coerceOutput(Object object) throws TemplateOutputCastException {
try {
return (T) Urn.createFromString((String) object);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.linkedin.metadata.validator;

import com.linkedin.common.urn.Urn;
import com.linkedin.data.schema.ArrayDataSchema;
import com.linkedin.data.schema.DataSchema;
import com.linkedin.data.schema.RecordDataSchema;
Expand Down Expand Up @@ -60,10 +61,11 @@ public static void validateSnapshotSchema(@Nonnull Class<? extends RecordTemplat
*
* @param snapshotClasses a collection of snapshot classes.
*/
public static void validateUniqueUrn(@Nonnull Collection<? extends Class> snapshotClasses) {
Set<Class> urnClasses = new HashSet<>();
public static void validateUniqueUrn(@Nonnull Collection<Class<? extends RecordTemplate>> snapshotClasses) {
final Set<Class<Urn>> urnClasses = new HashSet<>();
snapshotClasses.forEach(snapshotClass -> {
Class urnClass = ValidationUtils.getUrnClass(ValidationUtils.getRecordSchema(snapshotClass).getField("urn"));
final Class<Urn> urnClass =
ValidationUtils.getUrnClass(ValidationUtils.getRecordSchema(snapshotClass).getField("urn"));
if (urnClasses.contains(urnClass)) {
ValidationUtils.invalidSchema("URN class %s in %s has already been claimed by another snapshot.", urnClass,
snapshotClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ public static boolean isValidUrnField(@Nonnull RecordDataSchema.Field field, @No
/**
* Returns the Java class for an URN typeref field.
*/
public static Class getUrnClass(@Nonnull RecordDataSchema.Field field) {
public static Class<Urn> getUrnClass(@Nonnull RecordDataSchema.Field field) {
try {
return Class.forName(((DataMap) field.getType().getProperties().get("java")).getString("class"));
@SuppressWarnings("unchecked")
final Class<Urn> clazz =
(Class<Urn>) Class.forName(((DataMap) field.getType().getProperties().get("java")).getString("class"));
return clazz;
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
Expand Down