Skip to content

Commit d0c12df

Browse files
committed
Make all beans proxyable
The beans had private constructors, this makes them unproxyable according to CDI spec and may cause problems when instantiating them, requiring special unsafe handling and similar things.
1 parent ad55836 commit d0c12df

File tree

60 files changed

+147
-267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+147
-267
lines changed

config/pmd/pmd.xml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -253,19 +253,7 @@
253253
</property>
254254
</properties>
255255
</rule>
256-
<rule ref="category/java/errorprone.xml/MissingStaticMethodInNonInstantiatableClass">
257-
<properties>
258-
<property name="violationSuppressXPath">
259-
<value>
260-
.[
261-
ancestor::TypeDeclaration/Annotation[
262-
typeIsExactly('javax.enterprise.context.ApplicationScoped')
263-
or typeIsExactly('javax.enterprise.context.Dependent')]
264-
]
265-
</value>
266-
</property>
267-
</properties>
268-
</rule>
256+
<rule ref="category/java/errorprone.xml/MissingStaticMethodInNonInstantiatableClass"/>
269257
<rule ref="category/java/errorprone.xml/NullAssignment">
270258
<properties>
271259
<property name="violationSuppressXPath">

examples/simplePingBotJavacord/src/main/java/net/kautler/command/example/ping/JavacordProducer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2020 Björn Kautler
2+
* Copyright 2019-2022 Björn Kautler
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@
2727
import javax.inject.Named;
2828

2929
@ApplicationScoped
30-
public class JavacordProducer {
30+
class JavacordProducer {
3131
@Inject
3232
private Logger logger;
3333

examples/simplePingBotJavacord/src/main/java/net/kautler/command/example/ping/LoggerProducer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Björn Kautler
2+
* Copyright 2019-2022 Björn Kautler
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,9 +25,6 @@
2525

2626
@ApplicationScoped
2727
class LoggerProducer {
28-
private LoggerProducer() {
29-
}
30-
3128
@Produces
3229
private Logger getLogger(InjectionPoint injectionPoint) {
3330
return LogManager.getLogger(injectionPoint.getMember().getDeclaringClass());

examples/simplePingBotJavacord/src/main/java/net/kautler/command/example/ping/PingBot.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Björn Kautler
2+
* Copyright 2019-2022 Björn Kautler
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,13 +21,14 @@
2121
import javax.enterprise.inject.se.SeContainerInitializer;
2222
import javax.inject.Named;
2323

24+
import static java.lang.Boolean.FALSE;
2425
import static java.lang.Boolean.TRUE;
2526

2627
@ApplicationScoped
2728
public class PingBot {
2829
@Produces
2930
@Named
30-
public static String discordToken;
31+
private static String discordToken;
3132

3233
public static void main(String[] args) {
3334
if (args.length != 1) {
@@ -37,6 +38,7 @@ public static void main(String[] args) {
3738
discordToken = args[0];
3839
SeContainerInitializer.newInstance()
3940
.addProperty("javax.enterprise.inject.scan.implicit", TRUE)
41+
.addProperty("org.jboss.weld.construction.relaxed", FALSE)
4042
.initialize();
4143
}
4244
}

examples/simplePingBotJavacord/src/main/java/net/kautler/command/example/ping/PingCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import javax.inject.Inject;
2626

2727
@ApplicationScoped
28-
public class PingCommand implements Command<Message> {
28+
class PingCommand implements Command<Message> {
2929
@Inject
3030
private Logger logger;
3131

examples/simplePingBotJda/src/main/java/net/kautler/command/example/ping/JdaProducer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2020 Björn Kautler
2+
* Copyright 2019-2022 Björn Kautler
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@
2828
import javax.security.auth.login.LoginException;
2929

3030
@ApplicationScoped
31-
public class JdaProducer {
31+
class JdaProducer {
3232
@Inject
3333
private Logger logger;
3434

examples/simplePingBotJda/src/main/java/net/kautler/command/example/ping/LoggerProducer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Björn Kautler
2+
* Copyright 2019-2022 Björn Kautler
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,9 +25,6 @@
2525

2626
@ApplicationScoped
2727
class LoggerProducer {
28-
private LoggerProducer() {
29-
}
30-
3128
@Produces
3229
private Logger getLogger(InjectionPoint injectionPoint) {
3330
return LogManager.getLogger(injectionPoint.getMember().getDeclaringClass());

examples/simplePingBotJda/src/main/java/net/kautler/command/example/ping/PingBot.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Björn Kautler
2+
* Copyright 2019-2022 Björn Kautler
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,13 +21,14 @@
2121
import javax.enterprise.inject.se.SeContainerInitializer;
2222
import javax.inject.Named;
2323

24+
import static java.lang.Boolean.FALSE;
2425
import static java.lang.Boolean.TRUE;
2526

2627
@ApplicationScoped
2728
public class PingBot {
2829
@Produces
2930
@Named
30-
public static String discordToken;
31+
private static String discordToken;
3132

3233
public static void main(String[] args) {
3334
if (args.length != 1) {
@@ -37,6 +38,7 @@ public static void main(String[] args) {
3738
discordToken = args[0];
3839
SeContainerInitializer.newInstance()
3940
.addProperty("javax.enterprise.inject.scan.implicit", TRUE)
41+
.addProperty("org.jboss.weld.construction.relaxed", FALSE)
4042
.initialize();
4143
}
4244
}

examples/simplePingBotJda/src/main/java/net/kautler/command/example/ping/PingCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import javax.inject.Inject;
2626

2727
@ApplicationScoped
28-
public class PingCommand implements Command<Message> {
28+
class PingCommand implements Command<Message> {
2929
@Inject
3030
private Logger logger;
3131

readme/README_template.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ instances.
129129
_**Example:**_
130130
```java
131131
@ApplicationScoped
132-
public class JavacordProducer {
132+
class JavacordProducer {
133133
@Inject
134134
private Logger logger;
135135

@@ -170,7 +170,7 @@ produced `JDA` and / or `ShardManager` instances.
170170
_**Example:**_
171171
```java
172172
@ApplicationScoped
173-
public class JdaProducer {
173+
class JdaProducer {
174174
@Inject
175175
private Logger logger;
176176

@@ -208,7 +208,7 @@ Create a CDI bean that implements the [`Command`][Command JavaDoc] interface.
208208
_**Example:**_
209209
```java
210210
@ApplicationScoped
211-
public class PingCommand implements Command<Message> {
211+
class PingCommand implements Command<Message> {
212212
@Override
213213
public void execute(CommandContext<? extends Message> commandContext) {
214214
commandContext
@@ -276,16 +276,21 @@ like [`ChannelJavacord`][ChannelJavacord JavaDoc], [`RoleJavacord`][RoleJavacord
276276
_**Examples:**_
277277
```java
278278
@ApplicationScoped
279-
public class Vampire extends UserJavacord {
280-
private Vampire() {
279+
class Vampire extends UserJavacord {
280+
public Vampire() {
281281
super(341505207341023233L);
282282
}
283283
}
284284
```
285285

286286
```java
287287
@ApplicationScoped
288-
public class MyFancyServer extends ServerJavacord {
288+
class MyFancyServer extends ServerJavacord {
289+
// make bean proxyable according to CDI spec
290+
public MyFancyServer() {
291+
super(-1);
292+
}
293+
289294
@Inject
290295
private MyFancyServer(@Named("myFancyServerId") long myFancyServerId) {
291296
super(myFancyServerId);
@@ -381,7 +386,7 @@ _**Examples:**_
381386
```java
382387
@ApplicationScoped
383388
@Usage("<text...>")
384-
public class PingCommand implements Command<Message> {
389+
class PingCommand implements Command<Message> {
385390
@Inject
386391
private ParameterParser parameterParser;
387392

@@ -408,7 +413,7 @@ public class PingCommand implements Command<Message> {
408413
```java
409414
@ApplicationScoped
410415
@Usage("[<user:userMention>] ['exact']")
411-
public class DoCommand implements Command<Message> {
416+
class DoCommand implements Command<Message> {
412417
@Inject
413418
@Typed
414419
private ParameterParser parameterParser;
@@ -450,7 +455,7 @@ _**Examples:**_
450455
```java
451456
@ApplicationScoped
452457
@ParameterType("strings")
453-
public class StringsConverter implements ParameterConverter<Object, List<String>> {
458+
class StringsConverter implements ParameterConverter<Object, List<String>> {
454459
@Override
455460
public List<String> convert(String parameter, String type, CommandContext<?> commandContext) {
456461
return asList(parameter.split(","));
@@ -584,7 +589,7 @@ _**Examples:**_
584589
```java
585590
@ApplicationScoped
586591
@InPhase(BEFORE_PREFIX_COMPUTATION)
587-
public class MyPrefixTransformer implements CommandContextTransformer<Message> {
592+
class MyPrefixTransformer implements CommandContextTransformer<Message> {
588593
@Override
589594
public <T extends Message> CommandContext<T> transform(CommandContext<T> commandContext, Phase phase) {
590595
Optional<Server> server = commandContext.getMessage().getServer();
@@ -602,14 +607,14 @@ public class MyPrefixTransformer implements CommandContextTransformer<Message> {
602607
```java
603608
@ApplicationScoped
604609
@InPhase(BEFORE_PREFIX_COMPUTATION)
605-
public class MentionPrefixTransformer extends MentionPrefixTransformerJavacord {
610+
class MentionPrefixTransformer extends MentionPrefixTransformerJavacord {
606611
}
607612
```
608613

609614
```java
610615
@ApplicationScoped
611616
@InPhase(AFTER_ALIAS_AND_PARAMETER_STRING_COMPUTATION)
612-
public class MyAliasAndParameterStringTransformer implements CommandContextTransformer<Message> {
617+
class MyAliasAndParameterStringTransformer implements CommandContextTransformer<Message> {
613618
@Override
614619
public <T extends Message> CommandContext<T> transform(CommandContext<T> commandContext, Phase phase) {
615620
return (!commandContext.getAlias().isPresent())
@@ -651,7 +656,7 @@ not found.
651656
_**Example:**_
652657
```java
653658
@ApplicationScoped
654-
public class EventObserver {
659+
class EventObserver {
655660
private void commandNotFound(@ObservesAsync CommandNotFoundEventJavacord commandNotFoundEvent) {
656661
commandNotFoundEvent.getMessage()
657662
.getChannel()
@@ -673,7 +678,7 @@ allowed.
673678
_**Example:**_
674679
```java
675680
@ApplicationScoped
676-
public class EventObserver {
681+
class EventObserver {
677682
private void commandNotAllowed(@ObservesAsync CommandNotAllowedEventJavacord commandNotAllowedEvent) {
678683
commandNotAllowedEvent.getMessage()
679684
.getChannel()
@@ -699,7 +704,7 @@ extends the [`CommandHandler`][CommandHandler JavaDoc] class. You are also welco
699704
implementation to the library for all users benefit. You should read the JavaDoc of the `CommandHandler` class and have
700705
a look at any of the existing implementations to get started with writing your own implementation. Most of the common
701706
logic should be done in the `CommandHandler` class already and just some framework-dependent things like attaching
702-
message listeners to the underlying framework need to be done in the sub-class.
707+
message listeners to the underlying framework need to be done in the subclass.
703708

704709

705710

0 commit comments

Comments
 (0)