spring-projects / spring-projects/spring-data-rest

RepositoryNotFoundException thrown in the method objectToMapKey for java.lang.Long

Open
#66 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Retrieving a map resource of a class repository where the key of the map is of type Long, it fails due to a RepositoryNotFoundException that is thrown in the method objectToMapKey. The following piece of code is always throwing the exception looking for a repository for the class java.lang.Long:

 protected RepositoryMetadata repositoryMetadataFor(Class<?> domainType) {
   for(RepositoryExporter exporter : repositoryExporters) {
     RepositoryMetadata repoMeta = exporter.repositoryMetadataFor(domainType);
     if(null != repoMeta) {
       return repoMeta;
     }
   }
   throw new RepositoryNotFoundException("No repository found for type " + domainType.getName());
 }

This method is called in the objectToMapKey method of RestController:

if(ClassUtils.isAssignable(obj.getClass(), String.class)) {
     key = (String)obj;
   } else if(null != (repoMeta = repositoryMetadataFor(obj.getClass()))) {
     AttributeMetadata attrMeta = repoMeta.entityMetadata().idAttribute();
     String id = attrMeta.get(obj).toString();
     key = "@" + buildUri(config.getBaseUri(), repoMeta.name(), id);
   } else {
     key = conversionService.convert(obj, String.class);
   }

The conversionService is never executed.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in RestController.objectToMapKey and trace repositoryMetadataFor for a map resource whose key type is java.lang.Long. Reproduce the failure and inspect why the conversionService branch is unreachable. Done means Long map keys no longer trigger RepositoryNotFoundException and are converted as intended.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.