--- old/src/java.desktop/windows/native/libawt/windows/awt_Win32GraphicsDevice.h 2017-10-18 22:13:14.696268877 +0530 +++ new/src/java.desktop/windows/native/libawt/windows/awt_Win32GraphicsDevice.h 2017-10-18 22:13:14.480376870 +0530 @@ -119,6 +119,7 @@ float scaleY; static HDC MakeDCFromMonitor(HMONITOR); + static int CheckIntLimits(double value); }; #endif AWT_WIN32GRAPHICSDEVICE_H --- old/src/java.desktop/windows/native/libawt/windows/awt_Win32GraphicsDevice.cpp 2017-10-18 22:13:15.279976899 +0530 +++ new/src/java.desktop/windows/native/libawt/windows/awt_Win32GraphicsDevice.cpp 2017-10-18 22:13:15.044094890 +0530 @@ -632,22 +632,37 @@ int AwtWin32GraphicsDevice::ScaleUpX(int x) { - return (int)ceil(x * scaleX); + return CheckIntLimits(x * scaleX); } int AwtWin32GraphicsDevice::ScaleUpY(int y) { - return (int)ceil(y * scaleY); + return CheckIntLimits(y * scaleY); } int AwtWin32GraphicsDevice::ScaleDownX(int x) { - return (int)ceil(x / scaleX); + return CheckIntLimits(x / scaleX); } int AwtWin32GraphicsDevice::ScaleDownY(int y) { - return (int)ceil(y / scaleY); + return CheckIntLimits(y / scaleY); +} + +int AwtWin32GraphicsDevice::CheckIntLimits(double value) +{ + if (value < INT_MIN) + { + return INT_MIN; + } + + if (value > INT_MAX) + { + return INT_MAX; + } + + return (int)ceil(value); } void AwtWin32GraphicsDevice::InitDesktopScales() --- old/src/java.desktop/unix/classes/sun/awt/X11/XlibUtil.java 2017-10-18 22:13:15.891670921 +0530 +++ new/src/java.desktop/unix/classes/sun/awt/X11/XlibUtil.java 2017-10-18 22:13:15.639796912 +0530 @@ -38,6 +38,8 @@ import sun.awt.X11GraphicsDevice; import sun.awt.X11GraphicsEnvironment; +import sun.java2d.pipe.Region; + /* * This class is a collection of utility methods that operate * with native windows. @@ -414,6 +416,6 @@ } static int scaleDown(int x, int scale) { - return x / scale; + return Region.clipRound(x / (double)scale); } } --- old/src/java.desktop/unix/classes/sun/awt/X11GraphicsConfig.java 2017-10-18 22:13:16.459386941 +0530 +++ new/src/java.desktop/unix/classes/sun/awt/X11GraphicsConfig.java 2017-10-18 22:13:16.243494934 +0530 @@ -49,6 +49,7 @@ import sun.java2d.loops.RenderLoops; import sun.java2d.loops.SurfaceType; import sun.java2d.loops.CompositeType; +import sun.java2d.pipe.Region; import sun.java2d.x11.X11SurfaceData; import sun.awt.image.OffScreenImage; import sun.awt.image.SunVolatileImage; @@ -265,11 +266,11 @@ } public int scaleUp(int x) { - return x * getScale(); + return Region.clipRound(x * (double)getScale()); } public int scaleDown(int x) { - return x / getScale(); + return Region.clipRound(x / (double)getScale()); } /** --- old/src/java.desktop/unix/classes/sun/awt/X11/XDragSourceContextPeer.java 2017-10-18 22:13:16.999116961 +0530 +++ new/src/java.desktop/unix/classes/sun/awt/X11/XDragSourceContextPeer.java 2017-10-18 22:13:16.795218954 +0530 @@ -38,6 +38,7 @@ import java.util.*; +import sun.java2d.pipe.Region; import sun.util.logging.PlatformLogger; import sun.awt.dnd.SunDragSourceContextPeer; @@ -811,10 +812,10 @@ } public int scaleUp(int x) { - return x * windowScale; + return Region.clipRound(x * (double)windowScale); } public int scaleDown(int x) { - return x / windowScale; + return Region.clipRound(x / (double)windowScale); } }