Skip to content

Commit 3537b5a

Browse files
Remove deprecated methods from JodaCompatibleZonedDateTime which are called by scripts (#3346) (#3347)
Signed-off-by: Andriy Redko <andriy.redko@aiven.io> (cherry picked from commit c470580) Co-authored-by: Andriy Redko <andriy.redko@aiven.io>
1 parent 46ea3e9 commit 3537b5a

File tree

3 files changed

+20
-304
lines changed

3 files changed

+20
-304
lines changed

modules/lang-painless/src/main/resources/org/opensearch/painless/spi/org.opensearch.txt

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -124,29 +124,7 @@ class org.opensearch.script.JodaCompatibleZonedDateTime {
124124
ZonedDateTime withYear(int)
125125
ZonedDateTime withZoneSameLocal(ZoneId)
126126
ZonedDateTime withZoneSameInstant(ZoneId)
127-
128-
#### Joda time methods
129-
long getMillis()
130-
int getCenturyOfEra()
131-
int getEra()
132-
int getHourOfDay()
133-
int getMillisOfDay()
134-
int getMillisOfSecond()
135-
int getMinuteOfDay()
136-
int getMinuteOfHour()
137-
int getMonthOfYear()
138-
int getSecondOfDay()
139-
int getSecondOfMinute()
140-
int getWeekOfWeekyear()
141-
int getWeekyear()
142-
int getYearOfCentury()
143-
int getYearOfEra()
144-
String toString(String)
145-
String toString(String,Locale)
146-
147-
# conflicting methods
148127
DayOfWeek getDayOfWeekEnum()
149-
int getDayOfWeek()
150128
}
151129

152130
class org.opensearch.index.fielddata.ScriptDocValues$Dates {

server/src/main/java/org/opensearch/script/JodaCompatibleZonedDateTime.java

Lines changed: 0 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,9 @@
3232

3333
package org.opensearch.script;
3434

35-
import org.joda.time.DateTime;
3635
import org.opensearch.common.SuppressForbidden;
37-
import org.opensearch.common.SuppressLoggerChecks;
38-
import org.opensearch.common.logging.DeprecationLogger;
3936
import org.opensearch.common.time.DateFormatter;
40-
import org.opensearch.common.time.DateFormatters;
41-
import org.opensearch.common.time.DateUtils;
4237

43-
import java.security.AccessController;
44-
import java.security.PrivilegedAction;
4538
import java.time.DayOfWeek;
4639
import java.time.Instant;
4740
import java.time.LocalDate;
@@ -55,7 +48,6 @@
5548
import java.time.chrono.ChronoZonedDateTime;
5649
import java.time.chrono.Chronology;
5750
import java.time.format.DateTimeFormatter;
58-
import java.time.temporal.ChronoField;
5951
import java.time.temporal.Temporal;
6052
import java.time.temporal.TemporalAccessor;
6153
import java.time.temporal.TemporalAdjuster;
@@ -64,7 +56,6 @@
6456
import java.time.temporal.TemporalQuery;
6557
import java.time.temporal.TemporalUnit;
6658
import java.time.temporal.ValueRange;
67-
import java.util.Locale;
6859
import java.util.Objects;
6960

7061
/**
@@ -80,23 +71,6 @@ public class JodaCompatibleZonedDateTime
8071
TemporalAccessor {
8172

8273
private static final DateFormatter DATE_FORMATTER = DateFormatter.forPattern("strict_date_time");
83-
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(JodaCompatibleZonedDateTime.class);
84-
85-
private static void logDeprecated(String key, String message, Object... params) {
86-
AccessController.doPrivileged(new PrivilegedAction<Void>() {
87-
@SuppressLoggerChecks(reason = "safely delegates to logger")
88-
@Override
89-
public Void run() {
90-
deprecationLogger.deprecate(key, message, params);
91-
return null;
92-
}
93-
});
94-
}
95-
96-
private static void logDeprecatedMethod(String oldMethod, String newMethod) {
97-
logDeprecated(oldMethod, "Use of the joda time method [{}] is deprecated. Use [{}] instead.", oldMethod, newMethod);
98-
}
99-
10074
private ZonedDateTime dt;
10175

10276
public JodaCompatibleZonedDateTime(Instant instant, ZoneId zone) {
@@ -427,120 +401,7 @@ public ZonedDateTime withZoneSameInstant(ZoneId zone) {
427401
return dt.withZoneSameInstant(zone);
428402
}
429403

430-
@Deprecated
431-
public long getMillis() {
432-
logDeprecatedMethod("getMillis()", "toInstant().toEpochMilli()");
433-
return dt.toInstant().toEpochMilli();
434-
}
435-
436-
@Deprecated
437-
public int getCenturyOfEra() {
438-
logDeprecatedMethod("getCenturyOfEra()", "get(ChronoField.YEAR_OF_ERA) / 100");
439-
return dt.get(ChronoField.YEAR_OF_ERA) / 100;
440-
}
441-
442-
@Deprecated
443-
public int getEra() {
444-
logDeprecatedMethod("getEra()", "get(ChronoField.ERA)");
445-
return dt.get(ChronoField.ERA);
446-
}
447-
448-
@Deprecated
449-
public int getHourOfDay() {
450-
logDeprecatedMethod("getHourOfDay()", "getHour()");
451-
return dt.getHour();
452-
}
453-
454-
@Deprecated
455-
public int getMillisOfDay() {
456-
logDeprecatedMethod("getMillisOfDay()", "get(ChronoField.MILLI_OF_DAY)");
457-
return dt.get(ChronoField.MILLI_OF_DAY);
458-
}
459-
460-
@Deprecated
461-
public int getMillisOfSecond() {
462-
logDeprecatedMethod("getMillisOfSecond()", "get(ChronoField.MILLI_OF_SECOND)");
463-
return dt.get(ChronoField.MILLI_OF_SECOND);
464-
}
465-
466-
@Deprecated
467-
public int getMinuteOfDay() {
468-
logDeprecatedMethod("getMinuteOfDay()", "get(ChronoField.MINUTE_OF_DAY)");
469-
return dt.get(ChronoField.MINUTE_OF_DAY);
470-
}
471-
472-
@Deprecated
473-
public int getMinuteOfHour() {
474-
logDeprecatedMethod("getMinuteOfHour()", "getMinute()");
475-
return dt.getMinute();
476-
}
477-
478-
@Deprecated
479-
public int getMonthOfYear() {
480-
logDeprecatedMethod("getMonthOfYear()", "getMonthValue()");
481-
return dt.getMonthValue();
482-
}
483-
484-
@Deprecated
485-
public int getSecondOfDay() {
486-
logDeprecatedMethod("getSecondOfDay()", "get(ChronoField.SECOND_OF_DAY)");
487-
return dt.get(ChronoField.SECOND_OF_DAY);
488-
}
489-
490-
@Deprecated
491-
public int getSecondOfMinute() {
492-
logDeprecatedMethod("getSecondOfMinute()", "getSecond()");
493-
return dt.getSecond();
494-
}
495-
496-
@Deprecated
497-
public int getWeekOfWeekyear() {
498-
logDeprecatedMethod("getWeekOfWeekyear()", "get(DateFormatters.WEEK_FIELDS_ROOT.weekOfWeekBasedYear())");
499-
return dt.get(DateFormatters.WEEK_FIELDS_ROOT.weekOfWeekBasedYear());
500-
}
501-
502-
@Deprecated
503-
public int getWeekyear() {
504-
logDeprecatedMethod("getWeekyear()", "get(DateFormatters.WEEK_FIELDS_ROOT.weekBasedYear())");
505-
return dt.get(DateFormatters.WEEK_FIELDS_ROOT.weekBasedYear());
506-
}
507-
508-
@Deprecated
509-
public int getYearOfCentury() {
510-
logDeprecatedMethod("getYearOfCentury()", "get(ChronoField.YEAR_OF_ERA) % 100");
511-
return dt.get(ChronoField.YEAR_OF_ERA) % 100;
512-
}
513-
514-
@Deprecated
515-
public int getYearOfEra() {
516-
logDeprecatedMethod("getYearOfEra()", "get(ChronoField.YEAR_OF_ERA)");
517-
return dt.get(ChronoField.YEAR_OF_ERA);
518-
}
519-
520-
@Deprecated
521-
public String toString(String format) {
522-
logDeprecatedMethod("toString(String)", "a DateTimeFormatter");
523-
// TODO: replace with bwc formatter
524-
return new DateTime(dt.toInstant().toEpochMilli(), DateUtils.zoneIdToDateTimeZone(dt.getZone())).toString(format);
525-
}
526-
527-
@Deprecated
528-
public String toString(String format, Locale locale) {
529-
logDeprecatedMethod("toString(String,Locale)", "a DateTimeFormatter");
530-
// TODO: replace with bwc formatter
531-
return new DateTime(dt.toInstant().toEpochMilli(), DateUtils.zoneIdToDateTimeZone(dt.getZone())).toString(format, locale);
532-
}
533-
534404
public DayOfWeek getDayOfWeekEnum() {
535405
return dt.getDayOfWeek();
536406
}
537-
538-
@Deprecated
539-
public int getDayOfWeek() {
540-
logDeprecated(
541-
"getDayOfWeek()",
542-
"The return type of [getDayOfWeek()] will change to an enum in 7.0. Use getDayOfWeekEnum().getValue()."
543-
);
544-
return dt.getDayOfWeek().getValue();
545-
}
546407
}

0 commit comments

Comments
 (0)