function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
glorgeglorge 

Bug with <apex:outputText> tag in Visualforce

 The following Visualforce Page will fail to compile with the error message "Error: String index out of range: -40".

 

 

<apex:page standardController="Account">
  <apex:outputText value="Created Date: {0,Date,MMMMM dd, yyyy}, Modified Date: {1,Date,MMMMM dd, yyyy}, Created Date 2: {0,Date,MMMMM dd, yyyy}">
    <apex:param value="{!account.CreatedDate}" />
    <apex:param value="{!account.LastModifiedDate}" />
  </apex:outputText>
</apex:page> 

 

 

The following two variations, however, will compile just fine:

 

Variation 1:

 

 

<apex:page standardController="Account">
  <apex:outputText value="Created Date: {0,Date,MMMMM dd, yyyy}, Created Date 2: {0,Date,MMMMM dd, yyyy}, Modified Date: {1,Date,MMMMM dd, yyyy}">
    <apex:param value="{!account.CreatedDate}" />
    <apex:param value="{!account.LastModifiedDate}" />
  </apex:outputText>
</apex:page>

 

 

Variation 2:

 

 

<apex:page standardController="Account">
  <apex:outputText value="Created Date: {0,Date,MMMMM dd, yyyy}, Modified Date: {1,Date,MMMMM dd, yyyy}, Created Date 2: {2,Date,MMMMM dd, yyyy}">
    <apex:param value="{!account.CreatedDate}"/>
    <apex:param value="{!account.LastModifiedDate}"/>
    <apex:param value="{!account.CreatedDate}"/>
  </apex:outputText>
</apex:page> 

 

 

To my mind all three variations appear to be of valid syntax - and this is a bug with the implementation of pattern matching in the Visualforce <apex:outputText> tag implementation.

 

Note that while the above demonstrations are relatively abstract and may appear innocuous, when I encountered this bug "in the wild" on the email template I was working on it ended up taking two hours to isolate the problem due to the vagueness of the error message.  Compiler bugs (and I've encountered several working with Visualforce) should not be treated lightly.

SteveBowerSteveBower

Confirmed...  Looks like a bug to me.  Steve

 

 

 

 

<apex:page>

<!--   <apex:outputText value="{0}{1}{1}">	works. -->

<apex:outputText value="{0}{1}{0}">			<!--  Fails -->
    <apex:param value="A"/>
    <apex:param value="B"/>
  </apex:outputText>  
</apex:page>

 

Save error: String index out of range: -3