Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » ClassWeaver generates buggy code ?
ClassWeaver generates buggy code ? [message #1014877] Tue, 26 February 2013 16:22 Go to next message
J LM is currently offline J LMFriend
Messages: 11
Registered: December 2012
Junior Member
Hi,

using Findbugs as a quality code checker, it points me out that the generated code by the eclipselink weaver seems buggy. I use EclipseLink 2.3.3.

The two generated methods
_persistence_get
_persistence_set

use "==" instead of "equals" to compare two strings.

Example :
public Object _persistence_get(String paramString) {
    if (paramString == "myfield")
        return this.myfield;
    return null;
}


When looking at the code of the ClassWeaver class in the trunk of EclipseLink, the comments of the generation method shows clearly that this comparaison by "==" is intended.


    /**
     * Add an internal generic get and set method. This is used to avoid
     * reflection.
     * 
     * public Object _persistence_get(String attribute) { if (attribute ==
     * "address") { return this.address; } if (attribute == "city") { return
     * this.city; } return null; }
     *
     * public void _persistence_set(int index, Object value) { if (attribute ==
     * "address") { this.address = (String)value; } else if (attribute ==
     * "city") { this.city = (String)city; } }
     */
    public void addPersistenceGetSet(ClassDetails classDetails) {
.............


In fact, all the "if" conditions generated will be ignored. So the _get will always return null Sad

Any confirmation that this behavior is the one intended ?
If not, does this code can trigger unwanted behaviors or does it degrade gracefully (apparently yes but by execution of reflection code) ?


Thx,
Jul.

[Updated on: Tue, 26 February 2013 16:25]

Report message to a moderator

Re: ClassWeaver generates buggy code ? [message #1015116 is a reply to message #1014877] Wed, 27 February 2013 14:04 Go to previous message
J LM is currently offline J LMFriend
Messages: 11
Registered: December 2012
Junior Member
OK.
Forget about this thread.
Findbugs generates false positive. So I needed to make an exclude rules on weaved Entites.
This page confirmed me that this was the expected generated code :
http://wiki.eclipse.org/EclipseLink/DesignDocs/221546(2.0)#Reflection_Optimization

I was on wrong way when looking at the generated code with a decompiler.

Sorry for the noise.

Previous Topic:actually usable entity events
Next Topic:JPA-RS problem: java.lang.ClassCastException: java.util.ArrayList cannot be cast...
Goto Forum:
  


Current Time: Sun Nov 23 10:05:00 GMT 2014

Powered by FUDForum. Page generated in 0.01655 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software