-
-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Configuration bindings prints value but at runtime throws NullPointerException Version: 7.1.3 #409
Comments
Could you please prepare an example project? I tried to reproduce this, but it works. There must be some important specific in your project, not mentioned here. The same configuration introspection data is used for configuration report and for actual bindings, so if report shows something - it should be bound in context. Also, as it shows value in report, the same value must be bound - have no idea how null could be bound instead (and we could be sure that binding exists because otherwise guice would complain). You could also try to enable guice report: .printAllGuiceBindings() which shows all actual guice bindings (whreas configurtation report shows bindings that should be registered). It does not show the binding value (probably good idea for a new report), but you'll see if |
@Singleton
@RequiredArgsConstructor(onConstructor_ = @Inject)
@Slf4j
class DatasetServiceImpl implements DatasetService {
private static final String DATASET_ALREADY_EXISTS = "Dataset already exists";
private final @NonNull IdGenerator idGenerator;
private final @NonNull TransactionTemplate template;
private final @NonNull Provider<RequestContext> requestContext;
private final @NonNull EntitytDAO entityDAO;
private final @NonNull @Config BatchOperationsConfig batchOperationsConfig;
@Override
public DatasetPage find(int page, int size, @NonNull DatasetCriteria criteria) {
String workspaceId = requestContext.get().getWorkspaceId();
String userName = requestContext.get().getUserName();
int maxExperimentInClauseSize = batchOperationsConfig.getDatasets().getMaxExperimentInClauseSize();
//...
} Config class: @Getter
public class MyAPPConfiguration extends Configuration {
@Valid
@NotNull @JsonProperty
private DataSourceFactory database = new DataSourceFactory();
@Valid
@NotNull @JsonProperty
private CorsConfig cors = new CorsConfig();
@Valid
@NotNull @JsonProperty
private BatchOperationsConfig batchOperations = new BatchOperationsConfig();
} Lombok Config
Error
Log from print:
|
Sorry, I can't reproduce this. There must be some side effect: either One way to verify is by injecting @Singleton
@RequiredArgsConstructor(onConstructor_ = @Inject)
@Slf4j
class DatasetServiceImpl implements DatasetService {
private static final String DATASET_ALREADY_EXISTS = "Dataset already exists";
private final @NonNull IdGenerator idGenerator;
private final @NonNull TransactionTemplate template;
private final @NonNull Provider<RequestContext> requestContext;
private final @NonNull EntitytDAO entityDAO;
private final @NonNull @Config BatchOperationsConfig batchOperationsConfig;
private final @NonNull MyAPPConfiguration configuration;
@Override
public DatasetPage find(int page, int size, @NonNull DatasetCriteria criteria) {
String workspaceId = requestContext.get().getWorkspaceId();
String userName = requestContext.get().getUserName();
// must be the same instance
System.out.println(System.idenityHashCode(configuration.getBatchOperationsConfig()))
System.out.println(System.idenityHashCode(batchOperationsConfig))
// must both be null
System.out.println(configuration.getBatchOperationsConfig().getDatasets())
System.out.println(batchOperationsConfig().getDatasets())
int maxExperimentInClauseSize = batchOperationsConfig.getDatasets().getMaxExperimentInClauseSize();
//...
} If you'll make sure that Or, to avoid sharing project in public, you can send it directly to my email vyarus[at]gmail.com and I'll investigate the probelm. |
I just tested yesterday, it seems somehow related to docker. Out of the
container it works, or the JVM, in docker I'm using correto 21 2033
…On Sun, 10 Nov 2024, 11:01 Vyacheslav Rusakov, ***@***.***> wrote:
Sorry, I can't reproduce this. There must be some side effect: either
DatasetServiceImpl.batchOperationsConfig instance is different from
MyAPPConfiguration.batchOperations or somewhere
BatchOperationsConfig.setDatasets(null) is called.
One way to verify is by injecting MyAPPConfiguration in constructor to be
able to compare instances:
@***@***.***(onConstructor_ = @***@***.*** DatasetServiceImpl implements DatasetService {
private static final String DATASET_ALREADY_EXISTS = "Dataset already exists";
private final @nonnull IdGenerator idGenerator;
private final @nonnull TransactionTemplate template;
private final @nonnull Provider<RequestContext> requestContext;
private final @nonnull EntitytDAO entityDAO;
private final @nonnull @config BatchOperationsConfig batchOperationsConfig;
private final @nonnull MyAPPConfiguration configuration;
@OverRide
public DatasetPage find(int page, int size, @nonnull DatasetCriteria criteria) {
String workspaceId = requestContext.get().getWorkspaceId();
String userName = requestContext.get().getUserName();
// must be the same instance
System.out.println(System.idenityHashCode(configuration.getBatchOperationsConfig()))
System.out.println(System.idenityHashCode(batchOperationsConfig))
// must both be null
System.out.println(configuration.getBatchOperationsConfig().getDatasets())
System.out.println(batchOperationsConfig().getDatasets())
int maxExperimentInClauseSize = batchOperationsConfig.getDatasets().getMaxExperimentInClauseSize();
//...
}
If you'll make sure that BatchOperationsConfig is the same object then
something sets null into datasets: try to debug getter (or println inside
getter to track interactions)
Or, to avoid sharing project in public, you can send it directly to my
email vyarus[at]gmail.com and I'll investigate the probelm.
—
Reply to this email directly, view it on GitHub
<#409 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABSTONXY7PWHSG5BUS4ITM3Z74VHJAVCNFSM6AAAAABRLYTJYSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINRWGY3DQNJTGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
I run all tests with correto 21 and everything works (it would be very strange if it didn't). I assume that the simplest explanation could be server configuration file (yaml). No other ideas. Only debug on real case could help. |
I will try to create a public repo with this issue reproduced |
NullPointerException when @Inject a particular configuration property
The text was updated successfully, but these errors were encountered: