# Email templates: sptools.getClass behaviour

**URL:** <https://developer.sailpoint.com/discuss/t/email-templates-sptools-getclass-behaviour/115129>\
**Category:** SHF Discussion and Questions\
**Tags:** identity-security-cloud\
**Created:** [April 24, 2025, 5:51pm UTC](https://developer.sailpoint.com/discuss/t/email-templates-sptools-getclass-behaviour/115129 "2025-04-24T17:51:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Norris](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@David\_Norris](https://developer.sailpoint.com/discuss/u/David_Norris)\
**Post date:** [April 24, 2025, 5:51pm UTC](https://developer.sailpoint.com/discuss/t/email-templates-sptools-getclass-behaviour/115129/1 "2025-04-24T17:51:17Z")

</div>

I have the following lines at the top of an email template (testing out a strange behaviour I’m seeing):

```auto
#set($sdf = $spTools.getClass().forName("java.text.SimpleDateFormat").getInstance()) $sdf.getClass().getName()
#set($tz = $spTools.getClass().forName("java.util.TimeZone").getInstance()) $tz.getClass().getName()
#set($cal = $spTools.getClass().forName("java.util.Calendar").getInstance())$cal.getClass().getName()

```

But all that’s running is this ( **three times, identical** ):

```auto
java.text.SimpleDateFormat
java.text.SimpleDateFormat
java.text.SimpleDateFormat

```

Why is this happening?

---

<div class="post-metadata">

**Author:** ![narayanag](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/narayanag/32/25441_2.png) [@narayanag](https://developer.sailpoint.com/discuss/u/narayanag)\
**Post date:** [April 25, 2025, 7:08am UTC](https://developer.sailpoint.com/discuss/t/email-templates-sptools-getclass-behaviour/115129/2 "2025-04-25T07:08:54Z")

</div>

> [@David\_Norris](#):
>
> But all that’s running is this ( **three times, identical** ):
> 
> ```auto
> 
> ```

`getInstance()` in Java **does not necessarily return an instance of the base class**. It often returns a subclass.

---

<div class="post-metadata">

**Author:** ![narayanag](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/narayanag/32/25441_2.png) [@narayanag](https://developer.sailpoint.com/discuss/u/narayanag)\
**Post date:** [April 25, 2025, 7:14am UTC](https://developer.sailpoint.com/discuss/t/email-templates-sptools-getclass-behaviour/115129/3 "2025-04-25T07:14:09Z")

</div>

# What your code does:

#set($sdf = $spTools.getClass().forName(“java.text.SimpleDateFormat”).getInstance())  
$sdf.getClass().getName()  
This is trying to create an instance of SimpleDateFormat via Class.forName().getInstance()  
Then you’re printing out the class name to see what it actually created.

#set($tz = $spTools.getClass().forName(“java.util.TimeZone”).getInstance())  
$tz.getClass().getName()

Same idea for TimeZone.

#set($cal = $spTools.getClass().forName(“java.util.Calendar”).getInstance())  
$cal.getClass().getName()

And again for Calendar.

getInstance() in Java does not necessarily return an instance of the base class. It often returns a subclass.  
For example:

java.text.SimpleDateFormat.getInstance() → returns a pre-configured SimpleDateFormat object.

java.util.Calendar.getInstance() → returns an instance of GregorianCalendar.

java.util.TimeZone.getInstance() → returns the system’s default TimeZone, usually a subclass like sun.util.calendar.ZoneInfo (in Oracle JDK).

If you’re testing behavior:

$sdf.format($cal.time)  
$tz.getID()  
set specific formats/time zones to test behavior changes:

#set($sdf = $spTools.getClass().forName(“java.text.SimpleDateFormat”).newInstance())  
$sdf.applyPattern(“yyyy-MM-dd HH:mm:ss”)  
$sdf.format($cal.time)

Why the behavior might be strange:  
getInstance() in Java does not necessarily return an instance of the base class. It often returns a subclass.  
For example:

java.text.SimpleDateFormat.getInstance() → returns a pre-configured SimpleDateFormat object.

java.util.Calendar.getInstance() → returns an instance of GregorianCalendar.

java.util.TimeZone.getInstance() → returns the system’s default TimeZone, usually a subclass like sun.util.calendar.ZoneInfo (in Oracle JDK).

---

<div class="post-metadata">

**Author:** ![David\_Norris](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@David\_Norris](https://developer.sailpoint.com/discuss/u/David_Norris)\
**Post date:** [April 25, 2025, 1:15pm UTC](https://developer.sailpoint.com/discuss/t/email-templates-sptools-getclass-behaviour/115129/4 "2025-04-25T13:15:08Z")

</div>

That doesn’t seem to explain why java.text.SimpleDateFormat is returned for all three of them.

---

<div class="post-metadata">

**Author:** ![gmilunich](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/gmilunich/32/8431_2.png) [@gmilunich](https://developer.sailpoint.com/discuss/u/gmilunich)\
**Post date:** [June 10, 2025, 6:58pm UTC](https://developer.sailpoint.com/discuss/t/email-templates-sptools-getclass-behaviour/115129/5 "2025-06-10T18:58:03Z")

</div>

Where are you seeing that returned? In the UI for editing the EmailTemplate, or in the actual email that is sent?

---

<div class="post-metadata">

**Author:** ![gmilunich](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/gmilunich/32/8431_2.png) [@gmilunich](https://developer.sailpoint.com/discuss/u/gmilunich)\
**Post date:** [June 10, 2025, 7:02pm UTC](https://developer.sailpoint.com/discuss/t/email-templates-sptools-getclass-behaviour/115129/6 "2025-06-10T19:02:50Z")

</div>

I would consider changing it to split the calls. I have used this before and it works.

```auto
#set($calClass = $spTools.getClass().forName("java.util.Calendar"))
#set($TimeZoneClass = $spTools.getClass().forName("java.util.TimeZone"))
#set($NewCalInstance = $calClass.getInstance())
$NewCalInstance.setTime($certification.expiration)
...

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sailpoint/original/2X/f/f2136700ed5e3703e0b85e02f6be799dacca7735.png) [@system](https://developer.sailpoint.com/discuss/u/system)\
**Post date:** [August 9, 2025, 7:03pm UTC](https://developer.sailpoint.com/discuss/t/email-templates-sptools-getclass-behaviour/115129/7 "2025-08-09T19:03:27Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
