NullPointerException in TypeFactory.replaceAssociations for ComponentType

Description

The following code block will throw a NullPointerException when targetComponentValues should be determines and target[i] contains a NULL value.

else if ( types[i].isComponentType() ) {
// need to extract the component values and check for subtype replacements...
AbstractComponentType componentType = ( AbstractComponentType ) types[i];
Type[] subtypes = componentType.getSubtypes();
Object[] origComponentValues = original[i] == null ? new Object[subtypes.length] : componentType.getPropertyValues( original[i], session );
Object[] targetComponentValues = componentType.getPropertyValues( target[i], session );
replaceAssociations( origComponentValues, targetComponentValues, subtypes, session, null, copyCache, foreignKeyDirection );

This problem can be fixed the same way as it is prevented when origComponentValues are determined (see following line)
Object[] targetComponentValues = target[i] == null ? new Object[subtypes.length] : componentType.getPropertyValues( target[i], session );
copied[i] = target[i];
}

The problem did not exist in Version 3.2.2

Environment

None

Activity

Show:
Steve Ebersole
April 4, 2007, 6:43 PM

need a test case reproducing this

Reto Urfer
April 5, 2007, 8:37 PM

Attached zip file contains an eclipse project to reproduce the bug. the example uses hibenate jpa.

Gail Badner
April 19, 2007, 1:22 AM

I believe this is the same issue as HHH-2572. I've added a patch for a simpler test case to that ticket. I am currently testing the fix in this ticket to see if it works for that issue.

Gail Badner
April 19, 2007, 10:48 PM

I believe the suggested fix omits a line and should be as follows:

Object[] targetComponentValues = target[i] == null ? new Object[subtypes.length] : componentType.getPropertyValues( target[i], session );
replaceAssociations( origComponentValues, targetComponentValues, subtypes, session, null, copyCache, foreignKeyDirection );
copied[i] = target[i]

I am attaching a patch with this change for the Hibernate3_2 branch, HHH-2542.patch.

I have verified that the test case in works properly with this fix and that no other unit tests break.

I have not checked the test case attached to this issue because there were build errors ('ManyToOne' attribute 'ref' cannot be used in Embeddable object) and I wasn't sure of the versions of Annotations and Entity Manager that were being used.

Gail Badner
August 14, 2007, 9:54 PM

Fixed in trunk / 3.2.

Assignee

Gail Badner

Reporter

Reto Urfer

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure