1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
19
19
import java .io .FileNotFoundException ;
20
20
import java .io .IOException ;
21
21
import java .lang .annotation .Annotation ;
22
+ import java .net .SocketException ;
22
23
import java .net .UnknownHostException ;
23
24
import java .util .ArrayDeque ;
24
25
import java .util .ArrayList ;
@@ -458,7 +459,8 @@ private void processPropertySource(AnnotationAttributes propertySource) throws I
458
459
catch (IOException ex ) {
459
460
// Resource not found when trying to open it
460
461
if (ignoreResourceNotFound &&
461
- (ex instanceof FileNotFoundException || ex instanceof UnknownHostException )) {
462
+ (ex instanceof FileNotFoundException || ex instanceof UnknownHostException ||
463
+ ex instanceof SocketException )) {
462
464
if (logger .isInfoEnabled ()) {
463
465
logger .info ("Properties location [" + location + "] not resolvable: " + ex .getMessage ());
464
466
}
@@ -473,32 +475,35 @@ private void processPropertySource(AnnotationAttributes propertySource) throws I
473
475
private void addPropertySource (PropertySource <?> propertySource ) {
474
476
String name = propertySource .getName ();
475
477
MutablePropertySources propertySources = ((ConfigurableEnvironment ) this .environment ).getPropertySources ();
476
- if (propertySources .contains (name ) && this .propertySourceNames .contains (name )) {
478
+
479
+ if (this .propertySourceNames .contains (name )) {
477
480
// We've already added a version, we need to extend it
478
481
PropertySource <?> existing = propertySources .get (name );
479
- PropertySource <?> newSource = (propertySource instanceof ResourcePropertySource ?
480
- ((ResourcePropertySource ) propertySource ).withResourceName () : propertySource );
481
- if (existing instanceof CompositePropertySource ) {
482
- ((CompositePropertySource ) existing ).addFirstPropertySource (newSource );
483
- }
484
- else {
485
- if (existing instanceof ResourcePropertySource ) {
486
- existing = ((ResourcePropertySource ) existing ).withResourceName ();
482
+ if (existing != null ) {
483
+ PropertySource <?> newSource = (propertySource instanceof ResourcePropertySource ?
484
+ ((ResourcePropertySource ) propertySource ).withResourceName () : propertySource );
485
+ if (existing instanceof CompositePropertySource ) {
486
+ ((CompositePropertySource ) existing ).addFirstPropertySource (newSource );
487
+ }
488
+ else {
489
+ if (existing instanceof ResourcePropertySource ) {
490
+ existing = ((ResourcePropertySource ) existing ).withResourceName ();
491
+ }
492
+ CompositePropertySource composite = new CompositePropertySource (name );
493
+ composite .addPropertySource (newSource );
494
+ composite .addPropertySource (existing );
495
+ propertySources .replace (name , composite );
487
496
}
488
- CompositePropertySource composite = new CompositePropertySource (name );
489
- composite .addPropertySource (newSource );
490
- composite .addPropertySource (existing );
491
- propertySources .replace (name , composite );
497
+ return ;
492
498
}
493
499
}
500
+
501
+ if (this .propertySourceNames .isEmpty ()) {
502
+ propertySources .addLast (propertySource );
503
+ }
494
504
else {
495
- if (this .propertySourceNames .isEmpty ()) {
496
- propertySources .addLast (propertySource );
497
- }
498
- else {
499
- String firstProcessed = this .propertySourceNames .get (this .propertySourceNames .size () - 1 );
500
- propertySources .addBefore (firstProcessed , propertySource );
501
- }
505
+ String firstProcessed = this .propertySourceNames .get (this .propertySourceNames .size () - 1 );
506
+ propertySources .addBefore (firstProcessed , propertySource );
502
507
}
503
508
this .propertySourceNames .add (name );
504
509
}
@@ -675,7 +680,7 @@ SourceClass asSourceClass(Class<?> classType) throws IOException {
675
680
}
676
681
677
682
/**
678
- * Factory method to obtain {@link SourceClass}s from class names.
683
+ * Factory method to obtain a {@link SourceClass} collection from class names.
679
684
*/
680
685
private Collection <SourceClass > asSourceClasses (String [] classNames ) throws IOException {
681
686
List <SourceClass > annotatedClasses = new ArrayList <SourceClass >(classNames .length );
0 commit comments