anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: korpling/annis
Issue: Existence of directory is not checked when saving corpus properties

By default ANNIS (service) saves corpus properties in the directory `.annis/data` under the user's home directory. It does not ensure that the directory exists, nor do the installation instructions for public servers give any suggestion to create it. So the first time a user attempts to import a corpus, a `FileNotFoundException` is raised and the corpus.properties file is not saved. The fix is trivial.


Changed files:
annis-service/src/main/java/annis/dao/SpringAnnisDao.java

diff --git a/annis-service/src/main/java/annis/dao/SpringAnnisDao.java b/annis-service/src/main/java/annis/dao/SpringAnnisDao.java
index 7841746c1..99005e534 100644
--- a/annis-service/src/main/java/annis/dao/SpringAnnisDao.java
+++ b/annis-service/src/main/java/annis/dao/SpringAnnisDao.java
@@ -336,6 +336,17 @@ public class SpringAnnisDao extends SimpleJdbcDaoSupport implements AnnisDao,
 
 
     File dir = getRealDataDir();
+    if (!dir.exists())
+    {
+      if (dir.mkdirs())
+      {
+        log.info("Created directory " + dir);
+      }
+      else
+      {
+        log.error("Directory " + dir + " doesn't exist and cannot be created");
+      }
+    }
 
     if (fileName == null)
     {
Repository: metafacture/metafacture-core
Issue: Do not trim control field values in MARCXML handler.

Originally introduced in 5bdcd5d, this breaks positional access (`<substring>`) to control field data elements.

> For fixed-length fields with various kinds of coded information, specific data elements are positionally defined.

_— [MARC 21 Bibliographic - Control Fields](https://www.loc.gov/marc/bibliographic/bd00x.html)_

Related to #233.

Changed files:
metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlHandler.java
metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlHandlerTest.java

diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlHandler.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlHandler.java
index a79ecce6..76340b66 100644
--- a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlHandler.java
+++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlHandler.java
@@ -126,7 +126,7 @@ else if (DATAFIELD.equals(localName)) {
             getReceiver().endEntity();
         }
         else if (CONTROLFIELD.equals(localName)) {
-            getReceiver().literal(currentTag, builder.toString().trim());
+            getReceiver().literal(currentTag, builder.toString());
         }
         else if (RECORD.equals(localName) && checkNamespace(uri)) {
             getReceiver().endRecord();
diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlHandlerTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlHandlerTest.java
index 3902a604..8a9f8c86 100644
--- a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlHandlerTest.java
+++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlHandlerTest.java
@@ -77,6 +77,20 @@ public void shouldFindTagAttributeAtSecondPositionInControlFieldElement()
         verify(receiver).literal("001", fieldValue);
     }
 
+    @Test
+    public void issue440_shouldNotRemoveWhitespaceFromControlFields() throws SAXException {
+        final AttributesImpl attributes = new AttributesImpl();
+        attributes.addAttribute(NAMESPACE, "tag", "tag", "CDATA", "008");
+
+        final String fieldValue = "      t20202020au |||||||||||| ||||ger d";
+
+        marcXmlHandler.startElement(NAMESPACE, CONTROLFIELD, "", attributes);
+        marcXmlHandler.characters(fieldValue.toCharArray(), 0, fieldValue.length());
+        marcXmlHandler.endElement(NAMESPACE, CONTROLFIELD, "");
+
+        verify(receiver).literal("008", fieldValue);
+    }
+
     @Test
     public void issue233ShouldNotRemoveWhitespaceFromLeader()
             throws SAXException {