File tree 6 files changed +29
-12
lines changed
client/rest-high-level/src/main/java/org/elasticsearch/client/ml
main/java/org/elasticsearch/xpack/core/ml
test/java/org/elasticsearch/xpack/core/ml
6 files changed +29
-12
lines changed Original file line number Diff line number Diff line change @@ -286,11 +286,11 @@ public Builder(DatafeedConfig config) {
286
286
this .jobId = config .jobId ;
287
287
this .queryDelay = config .queryDelay ;
288
288
this .frequency = config .frequency ;
289
- this .indices = config .indices ;
290
- this .types = config .types ;
289
+ this .indices = config .indices == null ? null : new ArrayList <>( config . indices ) ;
290
+ this .types = config .types == null ? null : new ArrayList <>( config . types ) ;
291
291
this .query = config .query ;
292
292
this .aggregations = config .aggregations ;
293
- this .scriptFields = config .scriptFields ;
293
+ this .scriptFields = config .scriptFields == null ? null : new ArrayList <>( config . scriptFields ) ;
294
294
this .scrollSize = config .scrollSize ;
295
295
this .chunkingConfig = config .chunkingConfig ;
296
296
}
Original file line number Diff line number Diff line change 28
28
import org .elasticsearch .common .xcontent .XContentBuilder ;
29
29
30
30
import java .io .IOException ;
31
+ import java .util .ArrayList ;
31
32
import java .util .Collections ;
32
33
import java .util .Date ;
34
+ import java .util .HashMap ;
33
35
import java .util .List ;
34
36
import java .util .Map ;
35
37
import java .util .Objects ;
@@ -449,7 +451,7 @@ public Builder(String id) {
449
451
public Builder (Job job ) {
450
452
this .id = job .getId ();
451
453
this .jobType = job .getJobType ();
452
- this .groups = job .getGroups ();
454
+ this .groups = new ArrayList <>( job .getGroups () );
453
455
this .description = job .getDescription ();
454
456
this .analysisConfig = job .getAnalysisConfig ();
455
457
this .analysisLimits = job .getAnalysisLimits ();
@@ -463,7 +465,7 @@ public Builder(Job job) {
463
465
this .backgroundPersistInterval = job .getBackgroundPersistInterval ();
464
466
this .modelSnapshotRetentionDays = job .getModelSnapshotRetentionDays ();
465
467
this .resultsRetentionDays = job .getResultsRetentionDays ();
466
- this .customSettings = job .getCustomSettings ();
468
+ this .customSettings = job .getCustomSettings () == null ? null : new HashMap <>( job . getCustomSettings ()) ;
467
469
this .modelSnapshotId = job .getModelSnapshotId ();
468
470
this .resultsIndexName = job .getResultsIndexNameNoPrefix ();
469
471
this .deleting = job .getDeleting ();
Original file line number Diff line number Diff line change 38
38
import java .util .Collection ;
39
39
import java .util .Collections ;
40
40
import java .util .Comparator ;
41
+ import java .util .HashMap ;
41
42
import java .util .List ;
42
43
import java .util .Map ;
43
44
import java .util .Objects ;
@@ -461,14 +462,14 @@ public Builder(DatafeedConfig config) {
461
462
this .jobId = config .jobId ;
462
463
this .queryDelay = config .queryDelay ;
463
464
this .frequency = config .frequency ;
464
- this .indices = config .indices ;
465
- this .types = config .types ;
465
+ this .indices = new ArrayList <>( config .indices ) ;
466
+ this .types = new ArrayList <>( config .types ) ;
466
467
this .query = config .query ;
467
468
this .aggregations = config .aggregations ;
468
- this .scriptFields = config .scriptFields ;
469
+ this .scriptFields = config .scriptFields == null ? null : new ArrayList <>( config . scriptFields ) ;
469
470
this .scrollSize = config .scrollSize ;
470
471
this .chunkingConfig = config .chunkingConfig ;
471
- this .headers = config .headers ;
472
+ this .headers = new HashMap <>( config .headers ) ;
472
473
}
473
474
474
475
public void setId (String datafeedId ) {
Original file line number Diff line number Diff line change 32
32
import java .util .Collection ;
33
33
import java .util .Collections ;
34
34
import java .util .Date ;
35
+ import java .util .HashMap ;
35
36
import java .util .HashSet ;
36
37
import java .util .List ;
37
38
import java .util .Map ;
@@ -664,7 +665,7 @@ public Builder(Job job) {
664
665
this .id = job .getId ();
665
666
this .jobType = job .getJobType ();
666
667
this .jobVersion = job .getJobVersion ();
667
- this .groups = job .getGroups ();
668
+ this .groups = new ArrayList <>( job .getGroups () );
668
669
this .description = job .getDescription ();
669
670
this .analysisConfig = job .getAnalysisConfig ();
670
671
this .analysisLimits = job .getAnalysisLimits ();
@@ -678,7 +679,7 @@ public Builder(Job job) {
678
679
this .backgroundPersistInterval = job .getBackgroundPersistInterval ();
679
680
this .modelSnapshotRetentionDays = job .getModelSnapshotRetentionDays ();
680
681
this .resultsRetentionDays = job .getResultsRetentionDays ();
681
- this .customSettings = job .getCustomSettings ();
682
+ this .customSettings = job .getCustomSettings () == null ? null : new HashMap <>( job . getCustomSettings ()) ;
682
683
this .modelSnapshotId = job .getModelSnapshotId ();
683
684
this .resultsIndexName = job .getResultsIndexNameNoPrefix ();
684
685
this .deleting = job .isDeleting ();
Original file line number Diff line number Diff line change 6
6
package org .elasticsearch .xpack .core .ml .datafeed ;
7
7
8
8
import com .carrotsearch .randomizedtesting .generators .CodepointSetGenerator ;
9
-
10
9
import org .elasticsearch .ElasticsearchException ;
11
10
import org .elasticsearch .common .io .stream .NamedWriteableRegistry ;
12
11
import org .elasticsearch .common .io .stream .Writeable ;
@@ -490,6 +489,13 @@ public void testDefaultFrequency_GivenAggregationsWithHistogramInterval_1_Hour()
490
489
assertEquals (TimeValue .timeValueHours (1 ), datafeed .defaultFrequency (TimeValue .timeValueHours (12 )));
491
490
}
492
491
492
+ public void testCopyingDatafeedDoesNotCauseStackOverflow () {
493
+ DatafeedConfig datafeed = createTestInstance ();
494
+ for (int i = 0 ; i < 100000 ; i ++) {
495
+ datafeed = new DatafeedConfig .Builder (datafeed ).build ();
496
+ }
497
+ }
498
+
493
499
public static String randomValidDatafeedId () {
494
500
CodepointSetGenerator generator = new CodepointSetGenerator ("abcdefghijklmnopqrstuvwxyz" .toCharArray ());
495
501
return generator .ofCodePointsLength (random (), 10 , 10 );
Original file line number Diff line number Diff line change @@ -580,6 +580,13 @@ public void testEarliestValidTimestamp_GivenDataCountsAndLatency() {
580
580
assertThat (builder .build ().earliestValidTimestamp (dataCounts ), equalTo (123455789L ));
581
581
}
582
582
583
+ public void testCopyingJobDoesNotCauseStackOverflow () {
584
+ Job job = createRandomizedJob ();
585
+ for (int i = 0 ; i < 100000 ; i ++) {
586
+ job = new Job .Builder (job ).build ();
587
+ }
588
+ }
589
+
583
590
public static Job .Builder buildJobBuilder (String id , Date date ) {
584
591
Job .Builder builder = new Job .Builder (id );
585
592
builder .setCreateTime (date );
You can’t perform that action at this time.
0 commit comments