javafx detection uses TCCL but JavaFXPropertyValueUnwrapper does not

Description

When bootstrapping Hibernate Validator, ConfigurationImpl's constructor is called which contains:

The classloading mechanism used to implement method isJavaFxInClasspath() is inconsistent with that used in JavaFXPropertyValueUnwrapper constructor.

isJavaFxInClasspath uses the LoadClass util to check if the class javafx.application.Application exists. When this util fails to load the class through Class.forName it falls back to the ThreadContext ClassLoader.

JavaFXPropertyValueUnwrapper is a generic class parameterized with javafx.beans.value.ObservableValue. Its superclass constructor in TypeResolverBasedValueUnwrapper indirectly tries to load the ObservableValue class when resolving it's subclass type through classmate's TypeResolver. However, this does NOT fallback to the context class loader.

I have an Eclipse-based OSGi application that worked fine with Hibernate Validator 5.0.2.Final but fails bootstrapping Hibernate Validator with 5.2.1.Final due to this. I am not using javafx which means that the normal classloader cannot load javafx classes. Somehow the TCCL that Eclipse uses can load them leading to

A workaround for me is to temporarily set the TCCL to null or to the normal classloader.

Expected behavior would be for Hibernate Validator to should either successfully create the JavaFXPropertyValueUnwrapper or skip it, but not throw an exception when the TCCL differs from the normal classloader.

The exception I get:

Environment

None

Activity

Show:

Henno Vermeulen September 29, 2015 at 8:31 AM

I downloaded the snapshot hibernate-validator-5.3.0-20150927.062356-67.jar and I can confirm it solves the issue.

Henno Vermeulen September 24, 2015 at 2:40 PM
Edited

(EDIT: made some mistakes due to lack of time)

Hardy Ferentschik September 24, 2015 at 11:45 AM

, we merged the initial pull request. Would it be possible for you to try with 5.3.0-SNAPSHOT as a dependency? You find the SNAPSHOT in the JBoss Nexus Repo - http://repository.jboss.org/nexus/content/groups/public-jboss/org/hibernate/hibernate-validator/5.3.0-SNAPSHOT/

Gunnar Morling September 22, 2015 at 10:02 AM

Yes, right. It's included in JDK 8 and also in 7 for quite a while. We can do the reflective loading suggested in the PR, that may improve odds in a small number of cases.

Hardy Ferentschik September 22, 2015 at 7:54 AM

Yes, I suppose we should not fall back to the TCCL when detecting whether JavaFX is available or not, it's really the classloader of HV's classes which must be able to access the JavaFX types.

How so? Because you assume that the JacaFX classes are always part of the system classes?

Fixed

Assignee

Reporter

Bug Testcase Reminder (view)

Bug reports should generally be accompanied by a test case!

Bug Testcase Reminder (edit)

Bug reports should generally be accompanied by a test case!

Participants

Davide D'Alto
Gunnar Morling
Hardy Ferentschik
Henno Vermeulen

Components

Fix versions

Affects versions

Priority

Created September 15, 2015 at 10:34 AM
Updated September 29, 2015 at 8:38 AM
Resolved September 24, 2015 at 11:41 AM
Loading...