Skip to content

Commit 66cc3b2

Browse files
authored
Merge pull request quarkusio#48146 from eniuane/48133
Use DotName.toString() instead of Type.toString()
2 parents f57a982 + bf8c645 commit 66cc3b2

File tree

9 files changed

+59
-3
lines changed

9 files changed

+59
-3
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@defaultMessage Don't use Maven classes. They won't be available when using Gradle.
2+
org.apache.maven.**
3+
org.codehaus.plexus.**
4+
5+
@defaultMessage Never use Type#toString() as it's almost always the wrong thing to do. Usually org.jboss.jandex.DotName#toString() is what is needed
6+
org.jboss.jandex.Type#toString()
7+
8+
org.apache.commons.io.** @ Don't use commons-io dependency

independent-projects/arc/processor/pom.xml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,30 @@
6363
</dependency>
6464

6565
</dependencies>
66-
66+
<build>
67+
<plugins>
68+
<plugin>
69+
<groupId>de.thetaphi</groupId>
70+
<artifactId>forbiddenapis</artifactId>
71+
<executions>
72+
<execution>
73+
<id>verify-forbidden-apis</id>
74+
<configuration>
75+
<signaturesFiles>
76+
<signaturesFile>./banned-signatures.txt</signaturesFile>
77+
</signaturesFiles>
78+
<ignoreSignaturesOfMissingClasses>true</ignoreSignaturesOfMissingClasses>
79+
<suppressAnnotations>
80+
<annotation>**.SuppressForbidden</annotation>
81+
</suppressAnnotations>
82+
</configuration>
83+
<phase>compile</phase>
84+
<goals>
85+
<goal>check</goal>
86+
</goals>
87+
</execution>
88+
</executions>
89+
</plugin>
90+
</plugins>
91+
</build>
6792
</project>

independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ClientProxyGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ Collection<Resource> generate(BeanInfo bean, String beanClassName,
174174

175175
// Exceptions
176176
for (Type exception : method.exceptions()) {
177-
forward.addException(exception.toString());
177+
forward.addException(exception.name().toString());
178178
}
179179
// Method params
180180
ResultHandle[] params = new ResultHandle[method.parametersCount()];

independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ComponentsProviderGenerator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ void invokeAddMethod() {
551551
}
552552

553553
@Override
554+
@SuppressForbidden(reason = "Using Type.toString() to build an informative message")
554555
void addComponentInternal(BeanInfo removedBean) {
555556

556557
ResultHandle removedBeansHandle = addMethod.getMethodParam(0);
@@ -654,11 +655,13 @@ public void initialize(MethodCreator method) {
654655
}
655656

656657
@Override
658+
@SuppressForbidden(reason = "Using Type.toString() to build an informative message")
657659
public ResultHandle get(org.jboss.jandex.Type type, BytecodeCreator bytecode) {
658660
return bytecode.invokeInterfaceMethod(MethodDescriptors.MAP_GET, mapHandle, bytecode.load(type.toString()));
659661
}
660662

661663
@Override
664+
@SuppressForbidden(reason = "Using Type.toString() to build an informative message")
662665
public void put(org.jboss.jandex.Type type, ResultHandle value, BytecodeCreator bytecode) {
663666
bytecode.invokeInterfaceMethod(MethodDescriptors.MAP_PUT, mapHandle, bytecode.load(type.toString()), value);
664667
}

independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/InvokerGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,7 @@ static class CandidateMethods {
791791
this.invoker = invoker;
792792
}
793793

794+
@SuppressForbidden(reason = "Using Type.toString() to build an informative message")
794795
CandidateMethod resolve() {
795796
if (matching.size() == 1) {
796797
return matching.get(0);

independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ObserverGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public ObserverGenerator(AnnotationLiteralProcessor annotationLiterals, Predicat
9494
*
9595
* @param observer
9696
*/
97+
@SuppressForbidden(reason = "Using Type.toString() to build an informative message")
9798
void precomputeGeneratedName(ObserverInfo observer) {
9899
// The name of the generated class differs:
99100
// "org.acme.Foo_Observer_fooMethod_hash" for normal observer where hash represents the signature of the observer method

independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/SubclassGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ private void processDecorator(DecoratorInfo decorator, BeanInfo bean, Type provi
714714
MethodCreator forward = delegateSubclass.getMethodCreator(methodDescriptor);
715715
// Exceptions
716716
for (Type exception : method.exceptions()) {
717-
forward.addException(exception.toString());
717+
forward.addException(exception.name().toString());
718718
}
719719

720720
ResultHandle ret = null;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.quarkus.arc.processor;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* Used to suppress forbidden-apis errors inside the element it's added to.
10+
*/
11+
@Retention(RetentionPolicy.CLASS)
12+
@Target({ ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE })
13+
public @interface SuppressForbidden {
14+
String reason();
15+
}

independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/TypeImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
import org.jboss.jandex.DotName;
1414

15+
import io.quarkus.arc.processor.SuppressForbidden;
16+
1517
abstract class TypeImpl<JandexType extends org.jboss.jandex.Type> extends AnnotationTargetImpl implements Type {
1618
final JandexType jandexType;
1719

@@ -108,6 +110,7 @@ public Collection<AnnotationInfo> annotations() {
108110
}
109111

110112
@Override
113+
@SuppressForbidden(reason = "Using Type.toString() to build an informative message")
111114
public String toString() {
112115
return jandexType.toString();
113116
}

0 commit comments

Comments
 (0)