Hi

I've been looking at a potential memory leak - our heap dump shows millions
of org.apache.bval.jsr.valueextraction.ValueExtractors instances. I'm not
familiar with this structure, but upon doing some debugging, I can see a
tree structure being built up where each ValueExtractors object has several
children.

Its not clear to me what a ValueExtractor is or does, and I looked at both
the content in the heap, and also at the source code, so I'd appreciate a
couple of pointers there.

I was able to reproduce my issue in TomEE with a simple JAX-RS method:

@GET
public String doWork() {
 final Validator validator =
Validation.buildDefaultValidatorFactory().getValidator();
  ...
}

and just calling this method over and over.

It looks like this
causes org.apache.bval.jsr.ApacheValidatorFactory#getValidator() (
https://github.com/apache/bval/blob/2.0.3/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorFactory.java#L161)
to be called, which in turn calls usingContext(), which creates a new
ApacheFactoryContext, which in turn causes a new ValueExtractor to be
created and added to the Map on the ApacheValidatorFactory (
https://github.com/apache/bval/blob/2.0.3/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheFactoryContext.java#L66).
That ValueExtractor will live forever even when the ApacheFactoryContext
instance has gone out of scope, and the collection of ValueExtractors will
grow and grow.

I appreciate my example is not great as the validator can be injected or
looked up. Is it reasonable to obtain a validator in this way, or is it
against the spec? If its reasonable, is there some way this can be fixed?
I'm very happy to create a patch, but I'll likely need some pointers to get
started.

Thanks

Jon

Reply via email to