File tree 1 file changed +24
-4
lines changed
jre_emul/Classes/java/lang 1 file changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -798,10 +798,30 @@ public static void sleep(long millis) throws InterruptedException {
798
798
}
799
799
800
800
public static void sleep (long millis , int nanos ) throws InterruptedException {
801
- Object lock = currentThread ().vmThread ;
802
- synchronized (lock ) {
803
- lock .wait (millis , nanos );
804
- }
801
+ if (millis < 0 ) {
802
+ throw new IllegalArgumentException ("millis < 0: " + millis );
803
+ }
804
+ if (nanos < 0 ) {
805
+ throw new IllegalArgumentException ("nanos < 0: " + nanos );
806
+ }
807
+ if (nanos > 999999 ) {
808
+ throw new IllegalArgumentException ("nanos > 999999: " + nanos );
809
+ }
810
+
811
+ // The JLS 3rd edition, section 17.9 says: "...sleep for zero
812
+ // time...need not have observable effects."
813
+ if (millis == 0 && nanos == 0 ) {
814
+ // ...but we still have to handle being interrupted.
815
+ if (Thread .interrupted ()) {
816
+ throw new InterruptedException ();
817
+ }
818
+ return ;
819
+ }
820
+
821
+ Object lock = currentThread ().vmThread ;
822
+ synchronized (lock ) {
823
+ lock .wait (millis , nanos );
824
+ }
805
825
}
806
826
807
827
/**
You can’t perform that action at this time.
0 commit comments