A validation code used to return void in a WebObjects 4.5 application. However, in the converted WebObjects 5 application, the Java Converter coerces the void into a null causing validation issues.
Solution
The validation mechanism has changed in WebObjects 5.
In WebObjects 4.5 applications written in Objective-C, validation methods return an exception object if the target object is invalid, and receive a pointer to the target as their parameter. If coercion is necessary, the validation method would perform a side effect on its parameter. For applications written in Java, validation methods simply return void. If something is invalid, an EOValidation.Exception is thrown.
In WebObjects 5, this was changed to better accommodate the Java language. There are no side effects on the argument, and the return value is the desired, valid value. If something is invalid, an NSValidation.ValidationException must be thrown. Returning null will be interpreted as value coercion to the null Object reference.
Validation Examples
// Objective-C code in WebObjects 4.5
- (NSException *) validateStreetAddress: (NSString *) address;
// Java code in WebObjects 4.5
public void validateStreetAddress(String address) throws EOValidation.Exception;
// Proper conversion in WebObjects 5
// Returns the valid string object or throws NSValidation.ValidationException
// if the street address string is invalid.
public String validateStreetAddress(String address) throws NSValidation.ValidationException;
The WebObjects 5 Java Converter does not provide any warnings or errors when converting these validation methods. When converting a WebObjects 4.5 Java application to WebObjects 5 Java code, the converter does not properly change the WebObjects 4.5 void return method to a method returning the proper datatype. Since the method has no return value, EOF validation mechanism returns NULL and this leads to unwanted results at runtime.
Therefore, you should do a manual conversion based on the examples shown above in order for the EOValidation mechanism to function properly.