Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 298443 - Mapping Workbench generates wrong code if java.lang.Byte, Short, etc. used for inheritance
Summary: Mapping Workbench generates wrong code if java.lang.Byte, Short, etc. used fo...
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard: simple_fix, submitted_patch
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-22 17:10 EST by john.vandale CLA
Modified: 2022-06-09 10:20 EDT (History)
5 users (show)

See Also:


Attachments
patch fix and test (3.87 KB, patch)
2010-01-21 15:55 EST, john.vandale CLA
no flags Details | Diff
patch fix and test (5.24 KB, patch)
2010-01-21 17:33 EST, john.vandale CLA
peter.krogh: iplog+
Details | Diff
Minor comment and whitespace changes to previous patch (5.24 KB, patch)
2010-01-22 13:58 EST, David Minsky CLA
david.minsky: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description john.vandale CLA 2009-12-22 17:10:34 EST
Build Identifier: 2.0.0

If you export to Java source a project which has an inheritance relationship with class indicator types of java.lang.Byte, java.lang.Short, java.lang.Long, java.lang.Double, etc. the exported Java code will not compile due to an unrecognized constructor.

In the exported code the argument to the constructor for these classes is passed as a primitive type, i.e. int rather than as a String value.  For example if java.lang.Byte is the type for the indicator value the MW generates:

descriptor.getInheritancePolicy().addClassIndicator(model.LargeProject.class,
new java.lang.Byte(1));

which fails compilation because Byte(int) is not a java.lang.Byte constructor.

To fix this change this line in org.eclipse.persistence.sessions.factories.ProjectClassGenerator printString:

  return "new " + value.getClass().getName() + "(" + value + ")";

to:

  return "new " + value.getClass().getName() + "(\"" + value.toString() + "\")";

so the consructor which takes the String value is invoked.

Reproducible: Always

Steps to Reproduce:
1. Export to Java source a project which has an inheritance relationship and uses a class indicator value of type java.lang.Byte for that inheritance.

2.  View the generated source and note the "new java.lang.Byte(1)" described above.

3.  Try to compile this source file and see the error related to this constructor not being found.
Comment 1 Leslie Davis CLA 2010-01-19 19:06:19 EST
Reassigning because org.eclipse.persistence.sessions.factories.ProjectClassGenerator actually resides in the foundation runtime.
Comment 2 john.vandale CLA 2010-01-21 15:55:14 EST
Created attachment 156867 [details]
patch fix and test
Comment 3 john.vandale CLA 2010-01-21 17:33:40 EST
Created attachment 156880 [details]
patch fix and test
Comment 4 David Minsky CLA 2010-01-22 13:58:26 EST
Created attachment 156971 [details]
Minor comment and whitespace changes to previous patch
Comment 5 David Minsky CLA 2010-01-22 15:27:44 EST
Fix contributed by: John Vandale
EL IPLog updated

Reviewed: Guy Pelletier, David Minsky

Checked in: trunk (r6366 - http://fisheye2.atlassian.com/changelog/eclipselink/?cs=6366)
Code will be checked into 2.0
Comment 6 David Minsky CLA 2010-01-22 16:30:42 EST
Checked into 2.0 in revision 6367
http://fisheye2.atlassian.com/changelog/eclipselink/?cs=6367
Comment 7 Eclipse Webmaster CLA 2022-06-09 10:20:23 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink