struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Gainty (JIRA)" <>
Subject [jira] Created: (WW-3136) jsonplugin JSONResult.setIncludeProperties(String commaDelim) doesnt process includeProperties properly
Date Fri, 22 May 2009 13:56:44 GMT
jsonplugin JSONResult.setIncludeProperties(String commaDelim) doesnt process includeProperties

                 Key: WW-3136
             Project: Struts 2
          Issue Type: Bug
          Components: Other
    Affects Versions: 2.1.6
         Environment: JDK 6
latest json-plugin

            Reporter: Martin Gainty

//rather lengthy testcase for includeProperties

  public void testIncludePropertiesWithList() throws Exception {
        JSONResult result = new JSONResult();

/*public class JSONResult implements Result {
    private static final long serialVersionUID = 8624350183189931165L;
    private String defaultEncoding = "ISO-8859-1";
    private List<Pattern> includeProperties; //you want to initialise this!


/*** @param includedProperties the includeProperties to set
    public void setIncludeProperties(String commaDelim) {

        List<String> includePatterns = JSONUtil.asList(commaDelim);
//splits all Strings using , as delimiter
/*    public static List<String> asList(String commaDelim) {
        if ((commaDelim == null) || (commaDelim.trim().length() == 0))
            return null;
        List<String> list = new ArrayList<String>();
        String[] split = commaDelim.split(",");
        for (int i = 0; i < split.length; i++) {
            String trimmed = split[i].trim();
            if (trimmed.length() > 0) {
        return list;

        if (includePatterns != null)  //TRUE
            this.includeProperties = new ArrayList<Pattern>(includePatterns.size());
//includeProperties now includes ArrayList<Pattern>

            HashMap existingPatterns = new HashMap();

            for (String pattern : includePatterns) {
                // Compile a pattern for each *unique* "level" of the object
                // hierarchy specified in the regex.
                //split according to \ delimiter found
                String[] patternPieces = pattern.split("\\\\\\.");

                String patternExpr = "";

//the individual patternPieces will be referred to as patternPiece
                for (String patternPiece : patternPieces)
//patternExpr is null on first go-around (bypass this logic on first go-around)
                    if (patternExpr.length() > 0)
                        patternExpr += "\\."; 
                    patternExpr += patternPiece; //patternExpr=patternPiece

// Check for duplicate patterns so that there is no overlap.
//first go around will always execute logic as !existingPatterns returns true
                    if (!existingPatterns.containsKey(patternExpr))

//doesnt make sense..if existingPatterns already contains patternExpr why add it again?
//would'nt you want to leave existingPatterns HashMap alone?
                        existingPatterns.put(patternExpr, patternExpr);

//Add a pattern that does not have the indexed property matching (ie. list\[\d+\] //becomes

//look for the end in the piece we have
                     if (patternPiece.endsWith("\\]"))
//doesnt make're testing patternPiece.lastIndexOf("\\["))));
//then why compile patternExpr?
//why not take the relevant patternPiece and assign it to patternExpr
//then let the statement  later in the code this.includeProperties.add(Pattern.compile(patternExpr));
handle this?

//enable the log so we can see this message
    if (log.isDebugEnabled())
                                log.debug("Adding include property expression:  " + patternExpr.substring(0,

//this unconditionally adds the (compiled version of) patternExpr to includeProperties

                        if (log.isDebugEnabled())
                            log.debug("Adding include property expression:  " + patternExpr);

from what i can see there is a bug with JSONResult
public void setIncludeProperties(String commaDelim) method


This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message