Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
81e33dc8
Commit
81e33dc8
authored
Oct 25, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix NPE in url is null and no embedded database is available
Closes gh-10626
parent
33ff2407
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
26 deletions
+66
-26
EmbeddedDatabaseConnection.java
...k/boot/autoconfigure/jdbc/EmbeddedDatabaseConnection.java
+1
-1
DataSourceAutoConfigurationTests.java
.../autoconfigure/jdbc/DataSourceAutoConfigurationTests.java
+0
-24
DataSourcePropertiesTests.java
...rk/boot/autoconfigure/jdbc/DataSourcePropertiesTests.java
+17
-1
HidePackagesClassLoader.java
...work/boot/autoconfigure/jdbc/HidePackagesClassLoader.java
+48
-0
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDatabaseConnection.java
View file @
81e33dc8
...
@@ -106,7 +106,7 @@ public enum EmbeddedDatabaseConnection {
...
@@ -106,7 +106,7 @@ public enum EmbeddedDatabaseConnection {
*/
*/
public
String
getUrl
(
String
databaseName
)
{
public
String
getUrl
(
String
databaseName
)
{
Assert
.
hasText
(
databaseName
,
"DatabaseName must not be null."
);
Assert
.
hasText
(
databaseName
,
"DatabaseName must not be null."
);
return
String
.
format
(
this
.
url
,
databaseName
)
;
return
this
.
url
!=
null
?
String
.
format
(
this
.
url
,
databaseName
)
:
null
;
}
}
/**
/**
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java
View file @
81e33dc8
...
@@ -16,8 +16,6 @@
...
@@ -16,8 +16,6 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
jdbc
;
package
org
.
springframework
.
boot
.
autoconfigure
.
jdbc
;
import
java.net.URL
;
import
java.net.URLClassLoader
;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.Driver
;
import
java.sql.Driver
;
import
java.sql.DriverPropertyInfo
;
import
java.sql.DriverPropertyInfo
;
...
@@ -323,26 +321,4 @@ public class DataSourceAutoConfigurationTests {
...
@@ -323,26 +321,4 @@ public class DataSourceAutoConfigurationTests {
}
}
private
static
final
class
HidePackagesClassLoader
extends
URLClassLoader
{
private
final
String
[]
hiddenPackages
;
private
HidePackagesClassLoader
(
String
...
hiddenPackages
)
{
super
(
new
URL
[
0
],
DataSourceAutoConfigurationTests
.
class
.
getClassLoader
());
this
.
hiddenPackages
=
hiddenPackages
;
}
@Override
protected
Class
<?>
loadClass
(
String
name
,
boolean
resolve
)
throws
ClassNotFoundException
{
for
(
String
hiddenPackage
:
this
.
hiddenPackages
)
{
if
(
name
.
startsWith
(
hiddenPackage
))
{
throw
new
ClassNotFoundException
();
}
}
return
super
.
loadClass
(
name
,
resolve
);
}
}
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourcePropertiesTests.java
View file @
81e33dc8
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -16,7 +16,9 @@
...
@@ -16,7 +16,9 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
jdbc
;
package
org
.
springframework
.
boot
.
autoconfigure
.
jdbc
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -29,6 +31,9 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -29,6 +31,9 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
*/
public
class
DataSourcePropertiesTests
{
public
class
DataSourcePropertiesTests
{
@Rule
public
final
ExpectedException
thrown
=
ExpectedException
.
none
();
@Test
@Test
public
void
determineDriver
()
{
public
void
determineDriver
()
{
DataSourceProperties
properties
=
new
DataSourceProperties
();
DataSourceProperties
properties
=
new
DataSourceProperties
();
...
@@ -57,6 +62,17 @@ public class DataSourcePropertiesTests {
...
@@ -57,6 +62,17 @@ public class DataSourcePropertiesTests {
.
isEqualTo
(
EmbeddedDatabaseConnection
.
H2
.
getUrl
());
.
isEqualTo
(
EmbeddedDatabaseConnection
.
H2
.
getUrl
());
}
}
@Test
public
void
determineUrlWithNoEmbeddedSupport
()
throws
Exception
{
DataSourceProperties
properties
=
new
DataSourceProperties
();
properties
.
setBeanClassLoader
(
new
HidePackagesClassLoader
(
"org.h2"
,
"org.apache.derby"
,
"org.hsqldb"
));
properties
.
afterPropertiesSet
();
this
.
thrown
.
expect
(
DataSourceProperties
.
DataSourceBeanCreationException
.
class
);
this
.
thrown
.
expectMessage
(
"Cannot determine embedded database url"
);
properties
.
determineUrl
();
}
@Test
@Test
public
void
determineUrlWithExplicitConfig
()
throws
Exception
{
public
void
determineUrlWithExplicitConfig
()
throws
Exception
{
DataSourceProperties
properties
=
new
DataSourceProperties
();
DataSourceProperties
properties
=
new
DataSourceProperties
();
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/HidePackagesClassLoader.java
0 → 100644
View file @
81e33dc8
/*
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
jdbc
;
import
java.net.URL
;
import
java.net.URLClassLoader
;
/**
* Test {@link URLClassLoader} that hides configurable packages. No class in one of those
* packages or sub-packages are visible.
*
* @author Stephane Nicoll
*/
final
class
HidePackagesClassLoader
extends
URLClassLoader
{
private
final
String
[]
hiddenPackages
;
HidePackagesClassLoader
(
String
...
hiddenPackages
)
{
super
(
new
URL
[
0
],
DataSourceAutoConfigurationTests
.
class
.
getClassLoader
());
this
.
hiddenPackages
=
hiddenPackages
;
}
@Override
protected
Class
<?>
loadClass
(
String
name
,
boolean
resolve
)
throws
ClassNotFoundException
{
for
(
String
hiddenPackage
:
this
.
hiddenPackages
)
{
if
(
name
.
startsWith
(
hiddenPackage
))
{
throw
new
ClassNotFoundException
();
}
}
return
super
.
loadClass
(
name
,
resolve
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment