arne-bdt commented on code in PR #2798:
URL: https://github.com/apache/jena/pull/2798#discussion_r1817929455


##########
jena-core/src/main/java/org/apache/jena/ext/xerces/impl/validation/ValidationState.java:
##########
@@ -86,11 +85,25 @@ public void setSymbolTable(SymbolTable sTable) {
         fSymbolTable = sTable;
     }
 
+    /**
+     * Ensures that fIdTable and fIdRefTable are initialized.
+     */
+    private void ensureIdTablesAreInitialized() {
+        if (fIdTable == null) {
+            // REVISIT: Should replace with a lighter structure.
+            fIdTable = new HashMap();
+        }
+        if (fIdRefTable == null) {
+            fIdRefTable = new HashMap();
+        }
+    }
+
     /**
      * return null if all IDREF values have a corresponding ID value;
      * otherwise return the first IDREF value without a matching ID value.
      */
     public String checkIDRefID () {
+        ensureIdTablesAreInitialized();

Review Comment:
   Why init here? Instead:
   `if(fIdRefTable == null) return null;`
   
   and later in the while loop:
   
    if (fIdTable == null || !fIdTable.containsKey(key)) {



##########
jena-core/src/main/java/org/apache/jena/ext/xerces/impl/validation/ValidationState.java:
##########
@@ -169,16 +182,21 @@ public boolean isEntityUnparsed (String name) {
     // id
     @Override
     public boolean isIdDeclared(String name) {
+        if (fIdTable == null) {
+            return false;
+        }
         return fIdTable.containsKey(name);
     }
     @Override
     public void addId(String name) {
+        ensureIdTablesAreInitialized();

Review Comment:
   Only init fIdTable on demand here. 
   idRefTable is used in oder methods, so it might be that only one of the maps 
is needed.
   ```java
   if(fIdTable == null) {
       fIdTable = new HashMap();
   }
   ```



##########
jena-core/src/main/java/org/apache/jena/ext/xerces/impl/validation/ValidationState.java:
##########
@@ -169,16 +182,21 @@ public boolean isEntityUnparsed (String name) {
     // id
     @Override
     public boolean isIdDeclared(String name) {
+        if (fIdTable == null) {
+            return false;
+        }
         return fIdTable.containsKey(name);
     }
     @Override
     public void addId(String name) {
+        ensureIdTablesAreInitialized();
         fIdTable.put(name, fNullValue);
     }
 
     // idref
     @Override
     public void addIdRef(String name) {
+        ensureIdTablesAreInitialized();

Review Comment:
   Only init idRefTableon demand here. 
   fIdTable  is used in oder methods, so it might be that only one of the maps 
is needed.
   ```java
   if(idRefTable== null) {
       idRefTable= new HashMap();
   }
   ```



##########
jena-core/src/main/java/org/apache/jena/ext/xerces/impl/validation/ValidationState.java:
##########
@@ -86,11 +85,25 @@ public void setSymbolTable(SymbolTable sTable) {
         fSymbolTable = sTable;
     }
 
+    /**

Review Comment:
   This methos could be removed. The maps shoudl be individually created on 
demand, as they are used in differenct methods and not always togehter.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to