apache / apache/lucene

MMapDirectory not designed for inheritance [LUCENE-2799]

Open
#3,873 3 comments 0 reactions 0 assignees View on GitHub
affects-version:3.0.3 legacy-jira-priority:Major module:core/store type:enhancement
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

How to reproduce

Try to inherit from MMapDirectory to change the openInput logic (open files from different directories).

Expected result:

Inherit from MMapDirectory, overwrite the one method, done.

Actual result:

It's impossible to overwrite the method as the inner classes would be missing. It's impossible to fork the inner classes as they depend on a final method with default visibility (cleanMapping).
It turns out to be the easiest option to completely for the code and replace just the method in question.

Possible fix:

Change the visibility of most members and subtypes to be at least protected and avoid the default visibility.

---
Migrated from [LUCENE-2799](https://issues.apache.org/jira/browse/LUCENE-2799) by René Treffer

Contributor guide

Open the contributing guide

Research direction

Start by inspecting MMapDirectory and its openInput method, inner classes, and cleanMapping member. Trace which visibility and final-method constraints prevent subclassing, then define the smallest access changes that let a subclass override openInput without copying the inner classes. Done means the inheritance use case described in the issue is possible without forking the implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.