Hi

While reading LogMergePolicy I noticed that it uses IndexWriter's member and
method arg inconsistently:
1) Some methods that receive IW as a parameer, do: this.indexWriter =
indexWriter, and then use the member instance.
2) Others set the member instance, but continue to use the method arg.
3) Others don't set the member instance at all.
4) Some use the member, w/ the possibility of hitting NPE (if, say, the
findMerge* methods were not called yet).

As far as I understand, the member instance is defined just for methods that
need to use IW, but since the class does not require IW to be passed during
construction, they rely on one of the findMerge* methods to set the member
instance to the one they got. Is that right? I guess it is possible for the
same MergePolicy instance to receive different IW instances during its life
span, but is it something we should support?

Leaving back-compat aside for a moment, if a MP lives within an IndexWriter,
why not require an IW instance to be passed during an MP construction
(passing 'this' for IW own instantiation)? Then we can remove the IW method
arg and rely, safely, on the existence of IW.

Shai

Reply via email to