diff -r cc682329886b -r b0610cd08440 src/share/jaxws_classes/com/sun/xml/internal/rngom/digested/GrammarBuilderImpl.java --- a/src/share/jaxws_classes/com/sun/xml/internal/rngom/digested/GrammarBuilderImpl.java Thu Sep 26 10:43:28 2013 -0700 +++ b/src/share/jaxws_classes/com/sun/xml/internal/rngom/digested/GrammarBuilderImpl.java Fri Oct 04 16:21:34 2013 +0100 @@ -23,7 +23,7 @@ * questions. */ /* - * Copyright (C) 2004-2011 + * Copyright (C) 2004-2012 * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -45,6 +45,9 @@ */ package com.sun.xml.internal.rngom.digested; +import java.util.ArrayList; +import java.util.List; + import com.sun.xml.internal.rngom.ast.builder.Annotations; import com.sun.xml.internal.rngom.ast.builder.BuildException; import com.sun.xml.internal.rngom.ast.builder.CommentList; @@ -58,9 +61,6 @@ import com.sun.xml.internal.rngom.ast.util.LocatorImpl; import org.w3c.dom.Element; -import java.util.ArrayList; -import java.util.List; - /** * @author Kohsuke Kawaguchi (kk@kohsuke.org) */ @@ -85,12 +85,11 @@ } public ParsedPattern endGrammar(Location loc, Annotations anno) throws BuildException { - if(anno!=null) - grammar.annotation = ((Annotation)anno).getResult(); - if(additionalElementAnnotations!=null) { - if(grammar.annotation==null) - grammar.annotation = new DAnnotation(); - grammar.annotation.contents.addAll(additionalElementAnnotations); + // Harshit : Fixed possible NPE and issue in handling of annotations + if (anno != null) { + if (grammar.annotation != null) { + grammar.annotation.contents.addAll(((Annotation) anno).getResult().contents); + } } return grammar; } @@ -99,21 +98,28 @@ } public void define(String name, Combine combine, ParsedPattern pattern, Location loc, Annotations anno) throws BuildException { - if(name==START) + if(name==START) { grammar.start = (DPattern)pattern; - else { + } else { // TODO: handle combine DDefine d = grammar.getOrAdd(name); d.setPattern( (DPattern) pattern ); - if(anno!=null) + if (anno!=null) { d.annotation = ((Annotation)anno).getResult(); + } } } public void topLevelAnnotation(ParsedElementAnnotation ea) throws BuildException { - if(additionalElementAnnotations==null) + // Harshit : Fixed issue in handling of annotations + if (additionalElementAnnotations==null) { additionalElementAnnotations = new ArrayList(); + } additionalElementAnnotations.add(((ElementWrapper)ea).element); + if (grammar.annotation==null) { + grammar.annotation = new DAnnotation(); + } + grammar.annotation.contents.addAll(additionalElementAnnotations); } public void topLevelComment(CommentList comments) throws BuildException {