[fixes #3665] Add cast for null arguments

This commit is contained in:
Rawi01 committed 2024-05-24 00:58:35 +02:00
1 parent 30e19e4cdc
commit 52283d71cc
7 files changed
+70 -9

No files matched your search

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 The Project Lombok Authors.
* Copyright (C) 2021-2024 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -70,8 +70,10 @@ public class HandleStandardException extends EclipseAnnotationHandler<StandardEx
if (hasConstructor(typeNode) != MemberExistsResult.NOT_EXISTS) return;
int pS = source.get().sourceStart, pE = source.get().sourceEnd;
Expression messageArgument = new CastExpression(new NullLiteral(pS, pE), generateQualifiedTypeRef(source.get(), TypeConstants.JAVA_LANG_STRING));
Expression causeArgument = new CastExpression(new NullLiteral(pS, pE), generateQualifiedTypeRef(source.get(), TypeConstants.JAVA_LANG_THROWABLE));
ExplicitConstructorCall explicitCall = new ExplicitConstructorCall(ExplicitConstructorCall.This);
explicitCall.arguments = new Expression[] {new NullLiteral(pS, pE), new NullLiteral(pS, pE)};
explicitCall.arguments = new Expression[] {messageArgument, causeArgument};
ConstructorDeclaration constructor = createConstructor(level, typeNode, false, false, source, explicitCall, null);
injectMethod(typeNode, constructor);
}
@@ -81,8 +83,10 @@ public class HandleStandardException extends EclipseAnnotationHandler<StandardEx
int pS = source.get().sourceStart, pE = source.get().sourceEnd;
long p = (long) pS << 32 | pE;
Expression messageArgument = new SingleNameReference(MESSAGE, p);
Expression causeArgument = new CastExpression(new NullLiteral(pS, pE), generateQualifiedTypeRef(source.get(), TypeConstants.JAVA_LANG_THROWABLE));
ExplicitConstructorCall explicitCall = new ExplicitConstructorCall(ExplicitConstructorCall.This);
explicitCall.arguments = new Expression[] {new SingleNameReference(MESSAGE, p), new NullLiteral(pS, pE)};
explicitCall.arguments = new Expression[] {messageArgument, causeArgument};
ConstructorDeclaration constructor = createConstructor(level, typeNode, true, false, source, explicitCall, null);
injectMethod(typeNode, constructor);
}
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 The Project Lombok Authors.
* Copyright (C) 2021-2024 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -81,7 +81,9 @@ public class HandleStandardException extends JavacAnnotationHandler<StandardExce
if (hasConstructor(typeNode) != MemberExistsResult.NOT_EXISTS) return;
JavacTreeMaker maker = typeNode.getTreeMaker();
List<JCExpression> args = List.<JCExpression>of(maker.Literal(CTC_BOT, null), maker.Literal(CTC_BOT, null));
JCExpression stringArgument = maker.TypeCast(genJavaLangTypeRef(typeNode, "String"), maker.Literal(CTC_BOT, null));
JCExpression throwableArgument = maker.TypeCast(genJavaLangTypeRef(typeNode, "Throwable"), maker.Literal(CTC_BOT, null));
List<JCExpression> args = List.<JCExpression>of(stringArgument, throwableArgument);
JCStatement thisCall = maker.Exec(maker.Apply(List.<JCExpression>nil(), maker.Ident(typeNode.toName("this")), args));
JCMethodDecl constr = createConstructor(level, typeNode, false, false, source, List.of(thisCall));
injectMethod(typeNode, constr);
@@ -91,7 +93,9 @@ public class HandleStandardException extends JavacAnnotationHandler<StandardExce
if (hasConstructor(typeNode, String.class) != MemberExistsResult.NOT_EXISTS) return;
JavacTreeMaker maker = typeNode.getTreeMaker();
List<JCExpression> args = List.<JCExpression>of(maker.Ident(typeNode.toName("message")), maker.Literal(CTC_BOT, null));
JCExpression stringArgument = maker.Ident(typeNode.toName("message"));
JCExpression throwableArgument = maker.TypeCast(genJavaLangTypeRef(typeNode, "Throwable"), maker.Literal(CTC_BOT, null));
List<JCExpression> args = List.<JCExpression>of(stringArgument, throwableArgument);
JCStatement thisCall = maker.Exec(maker.Apply(List.<JCExpression>nil(), maker.Ident(typeNode.toName("this")), args));
JCMethodDecl constr = createConstructor(level, typeNode, true, false, source, List.of(thisCall));
injectMethod(typeNode, constr);
@@ -0,0 +1,25 @@
public class StandardExceptionWithConstructor extends Exception {
public StandardExceptionWithConstructor(Integer x, Integer y) {
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public StandardExceptionWithConstructor() {
this((java.lang.String) null, (java.lang.Throwable) null);
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public StandardExceptionWithConstructor(final java.lang.String message) {
this(message, (java.lang.Throwable) null);
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public StandardExceptionWithConstructor(final java.lang.Throwable cause) {
this(cause != null ? cause.getMessage() : null, cause);
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public StandardExceptionWithConstructor(final java.lang.String message, final java.lang.Throwable cause) {
super(message);
if (cause != null) super.initCause(cause);
}
}
@@ -0,0 +1,20 @@
import lombok.experimental.StandardException;
public @StandardException class StandardExceptionWithConstructor extends Exception {
public StandardExceptionWithConstructor(Integer x, Integer y) {
super();
}
public @java.lang.SuppressWarnings("all") @lombok.Generated StandardExceptionWithConstructor() {
this((java.lang.String) null, (java.lang.Throwable) null);
}
public @java.lang.SuppressWarnings("all") @lombok.Generated StandardExceptionWithConstructor(final java.lang.String message) {
this(message, (java.lang.Throwable) null);
}
public @java.lang.SuppressWarnings("all") @lombok.Generated StandardExceptionWithConstructor(final java.lang.Throwable cause) {
this(((cause != null) ? cause.getMessage() : null), cause);
}
public @java.lang.SuppressWarnings("all") @lombok.Generated StandardExceptionWithConstructor(final java.lang.String message, final java.lang.Throwable cause) {
super(message);
if ((cause != null))
super.initCause(cause);
}
}
@@ -2,10 +2,10 @@ import lombok.AccessLevel;
import lombok.experimental.StandardException;
@StandardException class EmptyException extends Exception {
public @java.lang.SuppressWarnings("all") @lombok.Generated EmptyException() {
this(null, null);
this((java.lang.String) null, (java.lang.Throwable) null);
}
public @java.lang.SuppressWarnings("all") @lombok.Generated EmptyException(final java.lang.String message) {
this(message, null);
this(message, (java.lang.Throwable) null);
}
public @java.lang.SuppressWarnings("all") @lombok.Generated EmptyException(final java.lang.Throwable cause) {
this(((cause != null) ? cause.getMessage() : null), cause);
@@ -21,7 +21,7 @@ import lombok.experimental.StandardException;
super();
}
protected @java.lang.SuppressWarnings("all") @lombok.Generated NoArgsException(final java.lang.String message) {
this(message, null);
this(message, (java.lang.Throwable) null);
}
protected @java.lang.SuppressWarnings("all") @lombok.Generated NoArgsException(final java.lang.Throwable cause) {
this(((cause != null) ? cause.getMessage() : null), cause);
@@ -0,0 +1,7 @@
import lombok.experimental.StandardException;
@StandardException
public class StandardExceptionWithConstructor extends Exception {
public StandardExceptionWithConstructor(Integer x, Integer y) {
}
}
@@ -0,0 +1 @@
4 The serializable class StandardExceptionWithConstructor does not declare a static final serialVersionUID field of type long