[OpenJDK 2D-Dev] RFR: JDK-8263362: Avoid division by 0 in java/awt/font/TextJustifier.java justify

Prasanta Sadhukhan psadhukhan at openjdk.java.net
Thu Mar 11 04:27:07 UTC 2021


On Wed, 10 Mar 2021 18:48:50 GMT, Phil Race <prr at openjdk.org> wrote:

>> Hi, I am not sure about the  weight > 0  check ; weight is initialized with 0:   weight = 0;   and later some values are potentially added up to weight:   weight += gi.weight;
>> I am not sure about those gi.weight values, maybe they can be negative too ?
>
> Nothing throws an exception or otherwise prevent this being negative but that would be a weird usage. Typically the weight is either zero or based on the font size .. which ought not to be negative but I don't think anything prevents it and I think we would treat it essentially as a transform. So If you really want to be careful here, then yes assume weight could be negative.

By that same logic, then shouldn't absorbweight also be checked as != 0 instead of > 0 as that also uses += gi.weight

-------------

PR: https://git.openjdk.java.net/jdk/pull/2912


More information about the 2d-dev mailing list