private static int mulPosAndCheck ( final int x , final int y ) { /* assert x>=0 && y>=0; */ final long m = ( long ) x * ( long ) y ; if ( m > Integer . MAX_VALUE ) { throw new ArithmeticException ( "overflow: mulPos" ) ; } return ( int ) m ; }
Multiply two non - negative integers checking for overflow .