From a3aa0185dad0990632d18315cd7d7974edb44dc4 Mon Sep 17 00:00:00 2001 From: John Plaisted Date: Tue, 3 Nov 2020 15:05:11 -0800 Subject: [PATCH] fix: turn on werror for restli-resources. --- build.gradle | 2 +- .../metadata/restli/BaseEntityResource.java | 3 +++ .../restli/BaseSearchableEntityResource.java | 1 + .../restli/BaseVersionedAspectResource.java | 1 + .../linkedin/metadata/restli/BrowsableClient.java | 1 + .../linkedin/metadata/restli/SearchableClient.java | 1 + .../restli/BaseBrowsableEntityResourceTest.java | 14 +++++++------- .../metadata/restli/BaseEntityResourceTest.java | 1 + .../restli/BaseSearchableEntityResourceTest.java | 3 ++- ...aseSingleAspectEntitySimpleKeyResourceTest.java | 4 ++-- .../restli/BaseVersionedAspectResourceTest.java | 6 +++++- 11 files changed, 25 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index fb8c44f20..475e57b36 100644 --- a/build.gradle +++ b/build.gradle @@ -74,7 +74,7 @@ def wErrorProjects = [ // project(':dao-impl:ebean-dao'), // project(':dao-impl:elasticsearch-dao'), // project(':dao-impl:neo4j-dao'), - // project(':restli-resources'), + project(':restli-resources'), project(':testing'), project(':validators') ] diff --git a/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseEntityResource.java b/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseEntityResource.java index 994e1cf9b..b60bbc3ae 100644 --- a/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseEntityResource.java +++ b/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseEntityResource.java @@ -180,6 +180,7 @@ public Task ingest(@ActionParam(PARAM_SNAPSHOT) @Nonnull SNAPSHOT snapshot protected Task ingestInternal(@Nonnull SNAPSHOT snapshot, @Nonnull Set> aspectsToIgnore) { return RestliUtils.toTask(() -> { + @SuppressWarnings("unchecked") final URN urn = (URN) ModelUtils.getUrnFromSnapshot(snapshot); final AuditStamp auditStamp = getAuditor().requestAuditStamp(getContext().getRawRequestContext()); ModelUtils.getAspectsFromSnapshot(snapshot).stream().forEach(aspect -> { @@ -222,6 +223,7 @@ public Task getSnapshot(@ActionParam(PARAM_URN) @Nonnull String urnStr * @deprecated Use {@link #backfill(String[], String[])} instead */ @Action(name = ACTION_BACKFILL_LEGACY) + @Deprecated @Nonnull public Task backfill(@ActionParam(PARAM_URN) @Nonnull String urnString, @ActionParam(PARAM_ASPECTS) @Optional @Nullable String[] aspectNames) { @@ -319,6 +321,7 @@ private IndexFilter getDefaultIndexFilter() { * @deprecated Use {@link #filter(IndexFilter, String[], String, PagingContext)} instead */ @Action(name = ACTION_LIST_URNS_FROM_INDEX) + @Deprecated @Nonnull public Task listUrnsFromIndex(@ActionParam(PARAM_FILTER) @Optional @Nullable IndexFilter indexFilter, @ActionParam(PARAM_URN) @Optional @Nullable String lastUrn, @ActionParam(PARAM_LIMIT) int limit) { diff --git a/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseSearchableEntityResource.java b/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseSearchableEntityResource.java index 0c3a5b471..23c5c1db7 100644 --- a/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseSearchableEntityResource.java +++ b/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseSearchableEntityResource.java @@ -123,6 +123,7 @@ public Task autocomplete(@ActionParam(PARAM_QUERY) @Nonnull return RestliUtils.toTask(() -> getSearchDAO().autoComplete(query, field, filter, limit)); } + @SuppressWarnings("unchecked") @Nonnull private CollectionResult getSearchQueryCollectionResult(@Nonnull SearchResult searchResult, @Nullable String[] aspectNames) { diff --git a/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseVersionedAspectResource.java b/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseVersionedAspectResource.java index 371788843..2e25ae266 100644 --- a/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseVersionedAspectResource.java +++ b/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseVersionedAspectResource.java @@ -150,6 +150,7 @@ public Task> createAndGet(@Nonnull Class */ @RestMethod.Create @ReturnEntity + @SuppressWarnings("unchecked") @Nonnull public Task> createIfAbsent(@Nonnull ASPECT defaultValue) { return createAndGet((Class) defaultValue.getClass(), ignored -> ignored.orElse(defaultValue)); diff --git a/restli-resources/src/main/java/com/linkedin/metadata/restli/BrowsableClient.java b/restli-resources/src/main/java/com/linkedin/metadata/restli/BrowsableClient.java index 1562b23c1..8251275a9 100644 --- a/restli-resources/src/main/java/com/linkedin/metadata/restli/BrowsableClient.java +++ b/restli-resources/src/main/java/com/linkedin/metadata/restli/BrowsableClient.java @@ -14,6 +14,7 @@ * * @deprecated Use {@link BaseBrowsableClient} instead */ +@Deprecated public interface BrowsableClient { @Nonnull diff --git a/restli-resources/src/main/java/com/linkedin/metadata/restli/SearchableClient.java b/restli-resources/src/main/java/com/linkedin/metadata/restli/SearchableClient.java index 739bb906a..cb7d48e8f 100644 --- a/restli-resources/src/main/java/com/linkedin/metadata/restli/SearchableClient.java +++ b/restli-resources/src/main/java/com/linkedin/metadata/restli/SearchableClient.java @@ -16,6 +16,7 @@ * @param the client's value type. * @deprecated Use {@link BaseSearchableClient} instead */ +@Deprecated public interface SearchableClient { @Nonnull diff --git a/restli-resources/src/test/java/com/linkedin/metadata/restli/BaseBrowsableEntityResourceTest.java b/restli-resources/src/test/java/com/linkedin/metadata/restli/BaseBrowsableEntityResourceTest.java index 7a5d9e93a..af08d2117 100644 --- a/restli-resources/src/test/java/com/linkedin/metadata/restli/BaseBrowsableEntityResourceTest.java +++ b/restli-resources/src/test/java/com/linkedin/metadata/restli/BaseBrowsableEntityResourceTest.java @@ -46,13 +46,13 @@ public TestResource() { @Nonnull @Override protected BaseLocalDAO getLocalDAO() { - throw new RuntimeException("Not implemented"); + throw new UnsupportedOperationException("Not implemented"); } @Nonnull @Override - protected BaseSearchDAO getSearchDAO() { - throw new RuntimeException("Not implemented"); + protected BaseSearchDAO getSearchDAO() { + throw new UnsupportedOperationException("Not implemented"); } @Nonnull @@ -74,25 +74,25 @@ protected Urn createUrnFromString(@Nonnull String urnString) { @Nonnull @Override protected Urn toUrn(@Nonnull ComplexResourceKey key) { - throw new RuntimeException("Not implemented"); + throw new UnsupportedOperationException("Not implemented"); } @Nonnull @Override protected ComplexResourceKey toKey(@Nonnull Urn urn) { - throw new RuntimeException("Not implemented"); + throw new UnsupportedOperationException("Not implemented"); } @Nonnull @Override protected EntityValue toValue(@Nonnull EntitySnapshot snapshot) { - throw new RuntimeException("Not implemented"); + throw new UnsupportedOperationException("Not implemented"); } @Nonnull @Override protected EntitySnapshot toSnapshot(@Nonnull EntityValue value, @Nonnull Urn urn) { - throw new RuntimeException("Not implemented"); + throw new UnsupportedOperationException("Not implemented"); } } diff --git a/restli-resources/src/test/java/com/linkedin/metadata/restli/BaseEntityResourceTest.java b/restli-resources/src/test/java/com/linkedin/metadata/restli/BaseEntityResourceTest.java index 21d13f7b4..a46e47f53 100644 --- a/restli-resources/src/test/java/com/linkedin/metadata/restli/BaseEntityResourceTest.java +++ b/restli-resources/src/test/java/com/linkedin/metadata/restli/BaseEntityResourceTest.java @@ -122,6 +122,7 @@ public ResourceContext getContext() { } @BeforeMethod + @SuppressWarnings("unchecked") public void setup() { _mockLocalDAO = mock(BaseLocalDAO.class); } diff --git a/restli-resources/src/test/java/com/linkedin/metadata/restli/BaseSearchableEntityResourceTest.java b/restli-resources/src/test/java/com/linkedin/metadata/restli/BaseSearchableEntityResourceTest.java index db158a4fc..779acaefd 100644 --- a/restli-resources/src/test/java/com/linkedin/metadata/restli/BaseSearchableEntityResourceTest.java +++ b/restli-resources/src/test/java/com/linkedin/metadata/restli/BaseSearchableEntityResourceTest.java @@ -68,7 +68,7 @@ protected BaseLocalDAO getLocalDAO() { @Nonnull @Override - protected BaseSearchDAO getSearchDAO() { + protected BaseSearchDAO getSearchDAO() { return _mockSearchDAO; } @@ -130,6 +130,7 @@ public ResourceContext getContext() { } @BeforeMethod + @SuppressWarnings("unchecked") public void setup() { _mockLocalDAO = mock(BaseLocalDAO.class); _mockSearchDAO = mock(BaseSearchDAO.class); diff --git a/restli-resources/src/test/java/com/linkedin/metadata/restli/BaseSingleAspectEntitySimpleKeyResourceTest.java b/restli-resources/src/test/java/com/linkedin/metadata/restli/BaseSingleAspectEntitySimpleKeyResourceTest.java index 764e998f4..533856ab7 100644 --- a/restli-resources/src/test/java/com/linkedin/metadata/restli/BaseSingleAspectEntitySimpleKeyResourceTest.java +++ b/restli-resources/src/test/java/com/linkedin/metadata/restli/BaseSingleAspectEntitySimpleKeyResourceTest.java @@ -36,7 +36,7 @@ import org.testng.annotations.Test; import static com.linkedin.common.AuditStamps.*; -import static com.linkedin.metadata.dao.BaseReadDAO.LATEST_VERSION; +import static com.linkedin.metadata.dao.BaseReadDAO.*; import static com.linkedin.testing.TestUtils.*; import static org.mockito.Mockito.*; import static org.testng.Assert.*; @@ -199,7 +199,7 @@ public void testGetAll() { ExtraInfo extraInfo2 = makeExtraInfo(makeUrn(2), LATEST_VERSION, makeAuditStamp("bar2")); ListResultMetadata listResultMetadata = new ListResultMetadata().setExtraInfos(new ExtraInfoArray(ImmutableList.of(extraInfo1, extraInfo2))); - ListResult listResult = ListResult.builder().values(bars).metadata(listResultMetadata).build(); + ListResult listResult = ListResult.builder().values(bars).metadata(listResultMetadata).build(); PagingContext pagingContext = new PagingContext(0, 2); when(_mockLocalDao.list(AspectBar.class, pagingContext.getStart(), pagingContext.getCount())).thenReturn(listResult); diff --git a/restli-resources/src/test/java/com/linkedin/metadata/restli/BaseVersionedAspectResourceTest.java b/restli-resources/src/test/java/com/linkedin/metadata/restli/BaseVersionedAspectResourceTest.java index 418590dcc..9b6a8abbc 100644 --- a/restli-resources/src/test/java/com/linkedin/metadata/restli/BaseVersionedAspectResourceTest.java +++ b/restli-resources/src/test/java/com/linkedin/metadata/restli/BaseVersionedAspectResourceTest.java @@ -63,6 +63,7 @@ public ResourceContext getContext() { } @BeforeMethod + @SuppressWarnings("unchecked") public void setup() { _mockLocalDAO = mock(BaseLocalDAO.class); } @@ -88,7 +89,8 @@ public void testGetAllWithMetadata() { new AuditStamp().setActor(Urns.createFromTypeSpecificString("testUser", "bar2")).setTime(0L)); ListResultMetadata listResultMetadata = new ListResultMetadata().setExtraInfos(new ExtraInfoArray(ImmutableList.of(extraInfo1, extraInfo2))); - ListResult listResult = ListResult.builder().values(foos).metadata(listResultMetadata).build(); + ListResult listResult = + ListResult.builder().values(foos).metadata(listResultMetadata).build(); when(_mockLocalDAO.list(AspectFoo.class, ENTITY_URN, 1, 2)).thenReturn(listResult); CollectionResult collectionResult = @@ -137,6 +139,7 @@ public void testCreateResponseViaLambda() { } @Test + @SuppressWarnings("unchecked") public void testCreateIfAbsentWithoutExistingValue() { AspectFoo defaultValue = new AspectFoo().setValue("foo"); when(_mockLocalDAO.add(eq(ENTITY_URN), eq(AspectFoo.class), any(), any())).thenAnswer( @@ -156,6 +159,7 @@ public void testCreateIfAbsentWithoutExistingValue() { } @Test + @SuppressWarnings("unchecked") public void testCreateIfAbsentWithExistingValue() { AspectFoo oldVal = new AspectFoo().setValue("foo"); AspectFoo defaultValue = new AspectFoo().setValue("defaultFoo");