Document existing exceptional behavior of divideUnsigned and remainderUnsigned

XMLWordPrintable

    • Type: CSR
    • Resolution: Approved
    • Priority: P4
    • 27
    • Component/s: core-libs
    • None
    • behavioral
    • minimal
    • Specify existing behavior in place since the methods were introduced.
    • Java API
    • SE

      Summary

      Add throws clauses to the specification of unsigned divide and remainder methods for a zero divisor.

      Problem

      While the divideUnsigned and remainderUnsigned methods for int and long have been implemented to throw ArithmeticException on a zero divsior, that behavior is not specified in a throws clause.

      Solution

      Add the appropriate throws clause to the affected methods.

      Specification

      diff --git a/src/java.base/share/classes/java/lang/Integer.java b/src/java.base/share/classes/java/lang/Integer.java
      index a9da1c32490..85ca80735f8 100644
      --- a/src/java.base/share/classes/java/lang/Integer.java
      +++ b/src/java.base/share/classes/java/lang/Integer.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 1994, 2025, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 1994, 2026, Oracle and/or its affiliates. All rights reserved.
        * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
        *
        * This code is free software; you can redistribute it and/or modify it
      @@ -1448,6 +1448,7 @@ public static long toUnsignedLong(int x) {
            * @param divisor the value doing the dividing
            * @return the unsigned quotient of the first argument divided by
            * the second argument
      +     * @throws ArithmeticException if the divisor is zero
            * @see #remainderUnsigned
            * @since 1.8
            */
      @@ -1466,6 +1467,7 @@ public static int divideUnsigned(int dividend, int divisor) {
            * @param divisor the value doing the dividing
            * @return the unsigned remainder of the first argument divided by
            * the second argument
      +     * @throws ArithmeticException if the divisor is zero
            * @see #divideUnsigned
            * @since 1.8
            */
      diff --git a/src/java.base/share/classes/java/lang/Long.java b/src/java.base/share/classes/java/lang/Long.java
      index c5cd9650f2d..5fa1b8fc2ea 100644
      --- a/src/java.base/share/classes/java/lang/Long.java
      +++ b/src/java.base/share/classes/java/lang/Long.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 1994, 2025, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 1994, 2026, Oracle and/or its affiliates. All rights reserved.
        * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
        *
        * This code is free software; you can redistribute it and/or modify it
      @@ -1411,6 +1411,7 @@ public static int compareUnsigned(long x, long y) {
            * @param divisor the value doing the dividing
            * @return the unsigned quotient of the first argument divided by
            * the second argument
      +     * @throws ArithmeticException if the divisor is zero
            * @see #remainderUnsigned
            * @since 1.8
            */
      @@ -1434,6 +1435,7 @@ public static long divideUnsigned(long dividend, long divisor) {
            * @param divisor the value doing the dividing
            * @return the unsigned remainder of the first argument divided by
            * the second argument
      +     * @throws ArithmeticException if the divisor is zero
            * @see #divideUnsigned
            * @since 1.8
            */
      

            Assignee:
            Joe Darcy
            Reporter:
            Joe Darcy
            Raffaello Giulietti
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: