Skip to content

Use sized array for List.toArray() #12153

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 @@ -137,7 +137,7 @@ public Flyway flyway() {
String password = getProperty(this.properties::getPassword,
this.dataSourceProperties::getPassword);
flyway.setDataSource(url, user, password,
this.properties.getInitSqls().toArray(new String[0]));
this.properties.getInitSqls().toArray(new String[this.properties.getInitSqls().size()]));
}
else if (this.flywayDataSource != null) {
flyway.setDataSource(this.flywayDataSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public ContextSource ldapContextSource() {

@Bean
public InMemoryDirectoryServer directoryServer() throws LDAPException {
String[] baseDn = this.embeddedProperties.getBaseDn().toArray(new String[0]);
String[] baseDn = this.embeddedProperties.getBaseDn().toArray(new String[this.embeddedProperties.getBaseDn().size()]);
InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(baseDn);
if (hasCredentials(this.embeddedProperties.getCredential())) {
config.addAdditionalBindCredentials(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public String[] selectImports(AnnotationMetadata importingClassMetadata) {
CouchbaseReactiveRepositoriesAutoConfiguration.class }) {
names.add(type.getName());
}
return names.toArray(new String[0]);
return names.toArray(new String[names.size()]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we write it using method reference as return names.toArray(String[]::new) ?

Copy link
Member

@wilkinsona wilkinsona Feb 21, 2018

Choose a reason for hiding this comment

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

No, I don't think so. AFAIK, you can't create an array using that syntax. Even if you could, it would presumably give you a 0-length array which would defeat the purpose of the change that @izeye is proposing.

Copy link
Contributor

@rajadilipkolli rajadilipkolli Feb 21, 2018

Choose a reason for hiding this comment

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

@wilkinsona You are correct, I mistook it

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public String[] selectImports(AnnotationMetadata importingClassMetadata) {
MongoRepositoriesAutoConfiguration.class }) {
names.add(type.getName());
}
return names.toArray(new String[0]);
return names.toArray(new String[names.size()]);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public String[] selectImports(AnnotationMetadata importingClassMetadata) {
MongoReactiveRepositoriesAutoConfiguration.class }) {
names.add(type.getName());
}
return names.toArray(new String[0]);
return names.toArray(new String[names.size()]);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public Builder packages(Class<?>... basePackageClasses) {
for (Class<?> type : basePackageClasses) {
packages.add(ClassUtils.getPackageName(type));
}
this.packagesToScan = packages.toArray(new String[0]);
this.packagesToScan = packages.toArray(new String[packages.size()]);
return this;
}

Expand Down