godtrue
posts - 229,comments - 165,views - 209万

实验环境说明:

1:JDK 1.8.0_241

2:IDEA IntelliJ 2018.3

3:Lombok 1.18.8

由于Fastjson漏洞比较多,所以,我调研换用Jackson是否OK,在实验的过程中发现了Lombok的一个细节,如果不注意,可能存在问题,问题比较简单,代码一贴基本就能看出来了!

4:源码如下所示

复制代码
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class TestLombok {
    private long _long;
    private Long _Long;

    private byte _byte;
    private Byte _Byte;

    private double _double;
    private Double _Double;

    private boolean _boolean;
    private Boolean _Boolean;

    private float _float;
    private Float _Float;

    private String myName;
    private String mYnAmE;
    private String MyNaMe;
    private String my_name;
}
复制代码

 

5:生成的反编译字节码如下所示

复制代码
public class TestLombok {
    private long _long;
    private Long _Long;
    private byte _byte;
    private Byte _Byte;
    private double _double;
    private Double _Double;
    private boolean _boolean;
    private Boolean _Boolean;
    private float _float;
    private Float _Float;
    private String myName;
    private String mYnAmE;
    private String MyNaMe;
    private String my_name;

    public long get_long() {
        return this._long;
    }

    public byte get_byte() {
        return this._byte;
    }

    public double get_double() {
        return this._double;
    }

    public boolean is_boolean() {
        return this._boolean;
    }

    public Boolean get_Boolean() {
        return this._Boolean;
    }

    public float get_float() {
        return this._float;
    }

    public String getMyName() {
        return this.myName;
    }

    public String getMy_name() {
        return this.my_name;
    }

    public void set_long(long _long) {
        this._long = _long;
    }

    public void set_byte(byte _byte) {
        this._byte = _byte;
    }

    public void set_double(double _double) {
        this._double = _double;
    }

    public void set_boolean(boolean _boolean) {
        this._boolean = _boolean;
    }

    public void set_float(float _float) {
        this._float = _float;
    }

    public void setMyName(String myName) {
        this.myName = myName;
    }

    public void setMy_name(String my_name) {
        this.my_name = my_name;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof TestLombok)) {
            return false;
        } else {
            TestLombok other = (TestLombok)o;
            if (!other.canEqual(this)) {
                return false;
            } else if (this.get_long() != other.get_long()) {
                return false;
            } else if (this.get_long() != other.get_long()) {
                return false;
            } else if (this.get_byte() != other.get_byte()) {
                return false;
            } else if (this.get_byte() != other.get_byte()) {
                return false;
            } else if (Double.compare(this.get_double(), other.get_double()) != 0) {
                return false;
            } else if (Double.compare(this.get_double(), other.get_double()) != 0) {
                return false;
            } else {
                label106: {
                    Object this$_boolean = this.get_Boolean();
                    Object other$_boolean = other.get_Boolean();
                    if (this$_boolean == null) {
                        if (other$_boolean == null) {
                            break label106;
                        }
                    } else if (this$_boolean.equals(other$_boolean)) {
                        break label106;
                    }

                    return false;
                }

                Object this$_Boolean = this.get_Boolean();
                Object other$_Boolean = other.get_Boolean();
                if (this$_Boolean == null) {
                    if (other$_Boolean != null) {
                        return false;
                    }
                } else if (!this$_Boolean.equals(other$_Boolean)) {
                    return false;
                }

                if (Float.compare(this.get_float(), other.get_float()) != 0) {
                    return false;
                } else if (Float.compare(this.get_float(), other.get_float()) != 0) {
                    return false;
                } else {
                    label89: {
                        Object this$myName = this.getMyName();
                        Object other$myName = other.getMyName();
                        if (this$myName == null) {
                            if (other$myName == null) {
                                break label89;
                            }
                        } else if (this$myName.equals(other$myName)) {
                            break label89;
                        }

                        return false;
                    }

                    Object this$mYnAmE = this.getMyName();
                    Object other$mYnAmE = other.getMyName();
                    if (this$mYnAmE == null) {
                        if (other$mYnAmE != null) {
                            return false;
                        }
                    } else if (!this$mYnAmE.equals(other$mYnAmE)) {
                        return false;
                    }

                    label75: {
                        Object this$MyNaMe = this.getMyName();
                        Object other$MyNaMe = other.getMyName();
                        if (this$MyNaMe == null) {
                            if (other$MyNaMe == null) {
                                break label75;
                            }
                        } else if (this$MyNaMe.equals(other$MyNaMe)) {
                            break label75;
                        }

                        return false;
                    }

                    Object this$my_name = this.getMy_name();
                    Object other$my_name = other.getMy_name();
                    if (this$my_name == null) {
                        if (other$my_name != null) {
                            return false;
                        }
                    } else if (!this$my_name.equals(other$my_name)) {
                        return false;
                    }

                    return true;
                }
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof TestLombok;
    }

    public int hashCode() {
        int PRIME = true;
        int result = 1;
        long $_long = this.get_long();
        int result = result * 59 + (int)($_long >>> 32 ^ $_long);
        long $_Long = this.get_long();
        result = result * 59 + (int)($_Long >>> 32 ^ $_Long);
        result = result * 59 + this.get_byte();
        result = result * 59 + this.get_byte();
        long $_double = Double.doubleToLongBits(this.get_double());
        result = result * 59 + (int)($_double >>> 32 ^ $_double);
        long $_Double = Double.doubleToLongBits(this.get_double());
        result = result * 59 + (int)($_Double >>> 32 ^ $_Double);
        Object $_boolean = this.get_Boolean();
        result = result * 59 + ($_boolean == null ? 43 : $_boolean.hashCode());
        Object $_Boolean = this.get_Boolean();
        result = result * 59 + ($_Boolean == null ? 43 : $_Boolean.hashCode());
        result = result * 59 + Float.floatToIntBits(this.get_float());
        result = result * 59 + Float.floatToIntBits(this.get_float());
        Object $myName = this.getMyName();
        result = result * 59 + ($myName == null ? 43 : $myName.hashCode());
        Object $mYnAmE = this.getMyName();
        result = result * 59 + ($mYnAmE == null ? 43 : $mYnAmE.hashCode());
        Object $MyNaMe = this.getMyName();
        result = result * 59 + ($MyNaMe == null ? 43 : $MyNaMe.hashCode());
        Object $my_name = this.getMy_name();
        result = result * 59 + ($my_name == null ? 43 : $my_name.hashCode());
        return result;
    }

    public String toString() {
        return "TestLombok(_long=" + this.get_long() + ", _Long=" + this.get_long() + ", _byte=" + this.get_byte() + ", _Byte=" + this.get_byte() + ", _double=" + this.get_double() + ", _Double=" + this.get_double() + ", _boolean=" + this.get_Boolean() + ", _Boolean=" + this.get_Boolean() + ", _float=" + this.get_float() + ", _Float=" + this.get_float() + ", myName=" + this.getMyName() + ", mYnAmE=" + this.getMyName() + ", MyNaMe=" + this.getMyName() + ", my_name=" + this.getMy_name() + ")";
    }

    public TestLombok() {
    }

    public TestLombok(long _long, Long _Long, byte _byte, Byte _Byte, double _double, Double _Double, boolean _boolean, Boolean _Boolean, float _float, Float _Float, String myName, String mYnAmE, String MyNaMe, String my_name) {
        this._long = _long;
        this._Long = _Long;
        this._byte = _byte;
        this._Byte = _Byte;
        this._double = _double;
        this._Double = _Double;
        this._boolean = _boolean;
        this._Boolean = _Boolean;
        this._float = _float;
        this._Float = _Float;
        this.myName = myName;
        this.mYnAmE = mYnAmE;
        this.MyNaMe = MyNaMe;
        this.my_name = my_name;
    }
}
复制代码

 

6:结论

     6-1:自动生成的Setter/Getter方法少了,貌似属性不区分大小写

     6-2:equals方法也是存在问题,某些属性的Getter方法使用错误

posted on   godtrue  阅读(3963)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示