spring-projects / spring-projects/spring-data-commons

Provide better handling of incompatible visibilities between domain type and repository

Open
#2,989 0 comments 1 reaction 1 assignee View on GitHub

@mp911de is already working on this.

Since Nov 27, 2023.

type: enhancement
Dominant language
Java
Stars
838
Forks
730
PR merge metrics
No merged PRs in 30d

Description

Related to #2526

Given a package-private entity

@Entity
class Book {

    @Id
    private String isbn;

    // no-args-constructor, getter, setter etc.
}

and a public repository with a custom findBy method

public interface BookRepository extends CrudRepository<Book, String> {

    Book findByIsbn(String isbn);
}

then the invocation of the findBy method fails with an error message that is more cryptic than helpful:

java.lang.IllegalAccessError: failed to access class org.example.Book from class jdk.proxy2.$Proxy105 (org.example.Book is in unnamed module of loader 'app'; jdk.proxy2.$Proxy105 is in module jdk.proxy2 of loader 'app')

The cause comes from the different visibilities. If the entity is public or the repository is package-private, it works.

I would expect this construct to work out of the box, because if the repository is package-private, it works again. Or provide a helpful error message at startup indicating the incompatible visibilities.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.