Skip to content

Added @Nullable annotation to overriding methods. #726

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
package org.springframework.batch.core.test.timeout;

import org.springframework.batch.item.ItemProcessor;
import org.springframework.lang.Nullable;

public class SleepingItemProcessor<I> implements ItemProcessor<I, I> {

private long millisToSleep;

@Nullable
@Override
public I process(I item) throws Exception {
Thread.sleep(millisToSleep);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.lang.Nullable;

public class SleepingTasklet implements Tasklet {

private long millisToSleep;

@Nullable
@Override
public RepeatStatus execute(StepContribution contribution,
ChunkContext chunkContext) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseConfigurer;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.lang.Nullable;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
Expand Down Expand Up @@ -154,13 +155,15 @@ public Flow flow() {
return new FlowBuilder<Flow>("flow")
.start(stepBuilderFactory.get("flow.step1")
.tasklet(new Tasklet() {
@Nullable
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
return RepeatStatus.FINISHED;
}
}).build()
).next(stepBuilderFactory.get("flow.step2")
.tasklet(new Tasklet() {
@Nullable
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
return RepeatStatus.FINISHED;
Expand All @@ -173,6 +176,7 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon
public Step firstStep() {
return stepBuilderFactory.get("firstStep")
.tasklet(new Tasklet() {
@Nullable
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
System.out.println(">> Beginning concurrent job test");
Expand All @@ -185,6 +189,7 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon
public Step lastStep() {
return stepBuilderFactory.get("lastStep")
.tasklet(new Tasklet() {
@Nullable
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
System.out.println(">> Ending concurrent job test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.springframework.batch.core.test.ldif;

import org.springframework.batch.item.ldif.RecordMapper;
import org.springframework.lang.Nullable;
import org.springframework.ldap.core.LdapAttributes;

/**
Expand All @@ -28,6 +29,7 @@
*/
public class MyMapper implements RecordMapper<LdapAttributes> {

@Nullable
public LdapAttributes mapRecord(LdapAttributes attributes) {
return attributes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.Nullable;
import org.springframework.ldap.core.LdapAttributes;
import org.springframework.test.context.junit4.SpringRunner;

Expand Down Expand Up @@ -210,6 +211,7 @@ public void handleRecord(LdapAttributes attributes) {
}

public class TestMapper implements RecordMapper<LdapAttributes> {
@Nullable
@Override
public LdapAttributes mapRecord(LdapAttributes attributes) {
return attributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.batch.core.UnexpectedJobExecutionException;
import org.springframework.batch.core.job.DefaultJobParametersValidator;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;

/**
Expand Down Expand Up @@ -149,6 +150,7 @@ public boolean isRestartable() {
/* (non-Javadoc)
* @see org.springframework.batch.core.Job#getJobParametersIncrementer()
*/
@Nullable
@Override
public JobParametersIncrementer getJobParametersIncrementer() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.lang.Nullable;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
Expand Down Expand Up @@ -189,6 +190,7 @@ public void clear() {
counter = -1;
}

@Nullable
@Override
public synchronized String read() throws Exception, UnexpectedInputException, ParseException {
counter++;
Expand Down Expand Up @@ -273,6 +275,7 @@ public void clear() {
jdbcTemplate.update("DELETE FROM ERROR_LOG where STEP_NAME='processed'");
}

@Nullable
@Override
public String process(String item) throws Exception {
processed.add(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.lang.Nullable;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
Expand Down Expand Up @@ -210,6 +211,7 @@ public void clear() {
counter = -1;
}

@Nullable
@Override
public synchronized String read() throws Exception, UnexpectedInputException, ParseException {
counter++;
Expand Down Expand Up @@ -305,6 +307,7 @@ public void clear() {
jdbcTemplate.update("DELETE FROM ERROR_LOG where STEP_NAME='processed'");
}

@Nullable
@Override
public String process(String item) throws Exception {
processed.add(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.support.ListItemReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.PlatformTransactionManager;
Expand Down Expand Up @@ -152,6 +153,7 @@ public void testExceptionInProcessDuringChunkScan() throws Exception {
ItemProcessor<Integer, Integer> itemProcessor = new ItemProcessor<Integer, Integer>() {
private int cpt;

@Nullable
@Override
public Integer process(Integer item) throws Exception {
cpt++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
import org.springframework.lang.Nullable;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.util.Assert;
Expand Down Expand Up @@ -176,6 +177,7 @@ public void clear() {
counter = -1;
}

@Nullable
@Override
public synchronized String read() throws Exception {
counter++;
Expand Down Expand Up @@ -236,6 +238,7 @@ public void clear() {
processed.clear();
}

@Nullable
@Override
public String process(String item) throws Exception {
processed.add(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
import org.springframework.lang.Nullable;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.util.Assert;
Expand Down Expand Up @@ -172,6 +173,7 @@ public void clear() {
counter = -1;
}

@Nullable
@Override
public synchronized String read() throws Exception, UnexpectedInputException, ParseException {
counter++;
Expand Down Expand Up @@ -226,6 +228,7 @@ public void clear() {
processed.clear();
}

@Nullable
@Override
public String process(String item) throws Exception {
processed.add(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.lang.Nullable;

/**
* @author Dave Syer
Expand Down Expand Up @@ -87,6 +88,7 @@ public static class CountingTasklet implements Tasklet {

private AtomicInteger count = new AtomicInteger(0);

@Nullable
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
contribution.incrementReadCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.springframework.batch.core.configuration.JobFactory;
import org.springframework.batch.core.configuration.JobRegistry;
import org.springframework.batch.core.launch.NoSuchJobException;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

/**
Expand Down Expand Up @@ -61,7 +62,7 @@ public void unregister(String name) {
}

@Override
public Job getJob(String name) throws NoSuchJobException {
public Job getJob(@Nullable String name) throws NoSuchJobException {
JobFactory factory = map.get(name);
if (factory == null) {
throw new NoSuchJobException("No job configuration with the name [" + name + "] was registered");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public JobExecution getLastJobExecution(JobInstance jobInstance) {
* (java.lang.String)
*/
@Override
public Set<JobExecution> findRunningJobExecutions(String jobName) {
public Set<JobExecution> findRunningJobExecutions(@Nullable String jobName) {
Set<JobExecution> executions = jobExecutionDao.findRunningJobExecutions(jobName);
for (JobExecution jobExecution : executions) {
getJobExecutionDependencies(jobExecution);
Expand All @@ -128,8 +128,9 @@ public Set<JobExecution> findRunningJobExecutions(String jobName) {
* org.springframework.batch.core.explore.JobExplorer#getJobExecution(java
* .lang.Long)
*/
@Nullable
@Override
public JobExecution getJobExecution(Long executionId) {
public JobExecution getJobExecution(@Nullable Long executionId) {
if (executionId == null) {
return null;
}
Expand All @@ -151,8 +152,9 @@ public JobExecution getJobExecution(Long executionId) {
* org.springframework.batch.core.explore.JobExplorer#getStepExecution(java
* .lang.Long)
*/
@Nullable
@Override
public StepExecution getStepExecution(Long jobExecutionId, Long executionId) {
public StepExecution getStepExecution(@Nullable Long jobExecutionId, @Nullable Long executionId) {
JobExecution jobExecution = jobExecutionDao.getJobExecution(jobExecutionId);
if (jobExecution == null) {
return null;
Expand All @@ -170,6 +172,7 @@ public StepExecution getStepExecution(Long jobExecutionId, Long executionId) {
* org.springframework.batch.core.explore.JobExplorer#getJobInstance(java
* .lang.Long)
*/
@Nullable
@Override
public JobInstance getJobInstance(@Nullable Long instanceId) {
return jobInstanceDao.getJobInstance(instanceId);
Expand All @@ -182,6 +185,7 @@ public JobInstance getJobInstance(@Nullable Long instanceId) {
* org.springframework.batch.core.explore.JobExplorer#getLastJobInstance(java
* .lang.String)
*/
@Nullable
@Override
public JobInstance getLastJobInstance(String jobName) {
return jobInstanceDao.getLastJobInstance(jobName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public String getName() {
* @param stepName name of the step
* @return the Step
*/
@Nullable
@Override
public abstract Step getStep(String stepName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.batch.core.step.StepLocator;
import org.springframework.lang.Nullable;

/**
* Simple implementation of {@link Job} interface providing the ability to run a
Expand Down Expand Up @@ -102,6 +103,7 @@ public void addStep(Step step) {
* @see
* org.springframework.batch.core.job.AbstractJob#getStep(java.lang.String)
*/
@Nullable
@Override
public Step getStep(String stepName) {
for (Step step : this.steps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.batch.core.job.SimpleStepHandler;
import org.springframework.batch.core.step.StepHolder;
import org.springframework.batch.core.step.StepLocator;
import org.springframework.lang.Nullable;

/**
* Implementation of the {@link Job} interface that allows for complex flows of
Expand Down Expand Up @@ -73,6 +74,7 @@ public void setFlow(Flow flow) {
/**
* {@inheritDoc}
*/
@Nullable
@Override
public Step getStep(String stepName) {
if (!initialized) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.batch.core.step.NoSuchStepException;
import org.springframework.batch.core.step.StepHolder;
import org.springframework.batch.core.step.StepLocator;
import org.springframework.lang.Nullable;

/**
* {@link State} implementation that delegates to a {@link FlowExecutor} to
Expand Down Expand Up @@ -99,6 +100,7 @@ public Collection<String> getStepNames() {
/* (non-Javadoc)
* @see org.springframework.batch.core.step.StepLocator#getStep(java.lang.String)
*/
@Nullable
@Override
public Step getStep(String stepName) throws NoSuchStepException {
Step result = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

/**
Expand Down Expand Up @@ -51,6 +52,7 @@ public void beforeStep(StepExecution stepExecution) {
}
}

@Nullable
@Override
public ExitStatus afterStep(StepExecution stepExecution) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.springframework.batch.core.step.NoSuchStepException;
import org.springframework.batch.core.step.StepLocator;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.lang.Nullable;

/**
* An extension of the {@link PartitionStep} that provides additional semantics
Expand Down Expand Up @@ -102,6 +103,7 @@ public Collection<String> getStepNames() {
/* (non-Javadoc)
* @see org.springframework.batch.core.step.StepLocator#getStep(java.lang.String)
*/
@Nullable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This @Nullable here does not make sense as the implementation throws NoSuchStepException when no step is found with the given name. The issue is that the behaviour is not consistent across the framework: some implementations return null (like SimpleJob) and some others throw NoSuchStepException like in here. I believe it is the contract StepLocator#getStep that should be fixed to throw an exception instead of returning null (in order to make it consistent with JobLocator), but my concern is that it would be a breaking change.

Copy link
Contributor

@fmbenhassine fmbenhassine Sep 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the contract StepLocator has been changed incorrectly here. I reverted that change and adapted the PR accordingly (See 2306141).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. Thanks for the changes.

@Override
public Step getStep(String stepName) throws NoSuchStepException {
JsrPartitionHandler partitionHandler = (JsrPartitionHandler) getPartitionHandler();
Expand Down
Loading