• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sun classes.

 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

One of the Utility class in our project is using Sun class to load some date time pattern i am not sure what it does as shown in the below code snippet.

This was working fine till JDK 1.5, but now i am migrating entire application to JDK 1.6 and this class seems to have changed. []



I want to remove this code which uses Sun class LocaleData but i am not able to find any alternative as i am not sure what it does exactly.

I tried to debug it on JDK 1.5 and for en_US locale it brings up the below String array

[HH:mm:ss 'o''clock' z, HH:mm:ss z, HH:mm:ss, HH:mm, EEEE, d MMMM yyyy, dd MMMM yyyy, dd-MMM-yyyy, dd/MM/yy, {1} {0}]

Is there any alternative to this ?
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What package was that class in?

edit Apparently continued from here. Jigar, when you post a follow-up question in a new thread, please provide a link to the earlier discussion to avoid repetition of advice.
 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it was in sun.text.resources.LocaleData

I found the alternative; copies those properties file containing patterns from Open JDK, and reading it through ResourceBundle.
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's good that you found a solution, but please see my edit in the first response, and my response on your earlier thread.
 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, that's the problem with badly written code. It's tough for maintainers. You'll have to examine the whole code base and see how they are using those patterns. They are probably using the patterns to instantiate SimpleDateFormat instances. If you're lucky, they're setting these all up in the same place. You can change those to DateFormat.getXxxInstance() calls, like DateFormat.getDateInstance(SHORT, myLocale).

On the other hand, you could just make literal Strings matching what you found in Java 1.5, and shove them in your patternTable. That kicks the rewriting job down the road a bit, but still leaves you with badly written code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic