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

Add log lines to help debug NPE in resolveLocationForPath #585

Merged
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -554,14 +554,27 @@ private String resolveNamespaceLocation(Namespace namespace, Map<String, String>
.map(
entity -> {
if (entity.getType().equals(PolarisEntityType.CATALOG)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor suggestion: would the code be cleaner if we put these into a new method like

  private static String baseLocation(PolarisEntity entity) {
    if (entity.getType().equals(PolarisEntityType.CATALOG)) {
      return CatalogEntity.of(entity).getDefaultBaseLocation();
    } else {
      String baseLocation =
          entity.getPropertiesAsMap().get(PolarisEntityConstants.ENTITY_BASE_LOCATION);
      if (baseLocation != null) {
        return baseLocation;
      } else {
        return entity.getName();
      }
    }
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good. Moved this logic to baseLocation helper!

return CatalogEntity.of(entity).getDefaultBaseLocation();
CatalogEntity catEntity = CatalogEntity.of(entity);
String catalogDefaultBaseLocation = catEntity.getDefaultBaseLocation();
if (catalogDefaultBaseLocation == null) {
LOGGER.warn(
"Tried to resolve location with catalog with null default base location. Catalog = {}",
catEntity);
}
return catalogDefaultBaseLocation;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should a catalog ever have a null base location? This feels like a case for PolarisDiagnostics.checkNotNull rather than a log statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too familiar and don't know if this should ever not happen but sounds good to use PolarisDiagnostics.checkNotNull. I'm adding some code

callContext
              .getPolarisCallContext().getDiagServices().checkNotNull

to get the diagnostic services to call checkNotNull though so please check if it's safe to do this or if we should be worried about NPEs.. It seems like elsewhere in the code we're assuming there aren't nulls when calling such methods.

Copy link
Contributor

@eric-maynard eric-maynard Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there was previously a bug where we were setting the base location to null; it could conceivably happen again. Agreed that this should be in checkNotNull or something similar though

It seems like elsewhere in the code we're assuming there aren't nulls when calling such methods.

Yes, I think we lean a little too heavily on the non-functional @nonnull annotation unfortunately. Adding more lightweight checks for this around is definitely a good idea

} else {
String baseLocation =
entity.getPropertiesAsMap().get(PolarisEntityConstants.ENTITY_BASE_LOCATION);
if (baseLocation != null) {
return baseLocation;
} else {
return entity.getName();
String entityName = entity.getName();
if (entityName == null) {
LOGGER.warn(
"Tried to resolve location with entity without base location or name. entity = {}",
entity);
}
return entityName;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here - there should never be an entity without a name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}
})
Expand Down
Loading