I don't know what's going wrong here. Which item is null? The font or the returned Integer? Where's the stack trace?
But it sounds as if a complete test case would be best. If its as you describe then it should be < 100 lines. If you want you can just send it directly to me, rather than the list. -phil. Peter B. West wrote:
I have encountered a difference in behaviour between 1.5 and 1.6 which seems to be related to the implementation of Font. I am creating Font objects from font files, using Font.createFont(font_format, font_file); and the setting the FONT attribute on an attributed to string to the Font so created. An AttributedString may have a number of FONT runs, and I need to recover the Font instance, and the offsets of change positions in the AttributedString. I process an AttributedCharacterIterator set up for the FONT attribute to get these inflection points and the associated Font. Each Font recovered I add to a Set and to a List. Set<Font> font_set = new HashSet<Font>(); List<Font> font_list = new LinkedList<Font>(); ... font_set.add(font); font_list.add(font); ... N.B. the above statements are contiguous in the code. I convert the font list into a array. Font[] fonts = new Font[0]; fonts = font_list.toArray( fonts ); Similarly, I construct an array from the elements of the set. Font[] font_array = new Font[0]; font_array = font_set.toArray( font_array ); I also have an array of the font boundary positions, which will correspond to the elements of the "fonts" array. The point of this is to allow me to represent the Font at any offset in the original string by a byte index into the array font_array. I need a map: Map<Font, Integer> font_map = new HashMap<Font, Integer>( font_set.size() ); For each Font in the (effective) set, font_array, I create a Map entry. font_map.put( font_array[ i ], Integer.valueOf( i ) ); The "fonts" array contains a element for each Font change position in the original AttributedString. To recover the byte index corresponding to one of these inflection points, I recover the corresponding Font by Font fnt = fonts[ inflection_point ]; This corresponds to an element from the original font_list List. I then get the index of this font from the font_map by: Integer index = font_map.get( fnt ); Quite aside from any questions of the wisdom of this approach, it works in 1.5. It fails with a NPE in 1.6. In 1.6 I can have entries in the fonts array, which is derived from the fonts_list, which match no key in the map. Why is it so? My understanding was the the same process ( .equals ) is involved in determining set membership as in determining the uniqueness of keys in a Map. What am I missing? And why does it work in 1.5? Peter =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA2D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA2D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".