package com.dropbox.core;

import com.dropbox.core.util.IOUtil;
import com.dropbox.core.util.StringUtil;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.regex.Pattern;

public class DbxSdkVersion
{
    public static final String Version;
    static {
        Version = loadVersion();
    }


    private static String loadVersion()
    {
        String version;
        InputStream in = DbxSdkVersion.class.getResourceAsStream("sdk-version.txt");
        try {
            BufferedReader bin = new BufferedReader(new InputStreamReader(in, StringUtil.UTF8));
            version = bin.readLine();
            if (version == null) throw new AssertionError("No lines in \"sdk-version.txt\".");
            String secondLine = bin.readLine();
            if (secondLine != null) throw new AssertionError("More than one line in \"sdk-version.txt\".  Second line: " + StringUtil.jq(secondLine));
        }
        catch (IOException ex) {
            throw new AssertionError("Error reading from \"sdk-version.txt\": " + ex.getMessage());
        }
        finally {
            IOUtil.closeInput(in);
        }

        Pattern versionRegex = Pattern.compile("[0-9]+(?:\\.[0-9]+)*(?:-[-_A-Za-z0-9]+)");
        if (!versionRegex.matcher(version).matches()) {
            throw new AssertionError("Version in \"sdk-version.txt\" doesn't follow expected pattern: " + StringUtil.jq(version));
        }

        return version;
    }
}

@@ -375,17 +375,16 @@
 %0A    %7D%0A%0A
-%0A
     priv
@@ -540,24 +540,114 @@
       try %7B%0A
+            if (in == null) throw new AssertionError(%22Not found.%22);%0A            try %7B%0A    
             
@@ -743,16 +743,20 @@
         
+    
 version 
@@ -765,32 +765,36 @@
 bin.readLine();%0A
+    
             if (
@@ -848,36 +848,17 @@
 ines
- in %5C%22sdk-version.txt%5C%22
 .%22);%0A
+    
     
@@ -893,32 +893,36 @@
 bin.readLine();%0A
+    
             if (
@@ -967,17 +967,23 @@
 nError(%22
-M
+Found m
 ore than
@@ -991,39 +991,16 @@
 one line
- in %5C%22sdk-version.txt%5C%22
 .  Secon
@@ -1051,153 +1051,18 @@
     
-%7D%0A        catch (IOException ex) %7B%0A            throw new AssertionError(%22Error reading from %5C%22sdk-version.txt%5C%22: %22 + ex.getMessage());
+    %7D
 %0A    
-    %7D%0A
     
@@ -1071,24 +1071,28 @@
   finally %7B%0A
+    
             
@@ -1114,35 +1114,43 @@
 ut(in);%0A        
-%7D%0A%0A
+    %7D%0A%0A    
         Pattern 
@@ -1228,24 +1228,28 @@
 %22);%0A        
+    
 if (!version
@@ -1296,16 +1296,20 @@
         
+    
 throw ne
@@ -1330,38 +1330,12 @@
 or(%22
-Version in %5C%22sdk-version.txt%5C%22
+Text
  doe
@@ -1389,24 +1389,199 @@
 (version));%0A
+            %7D%0A%0A        %7D%0A        catch (IOException ex) %7B%0A            throw new AssertionError(%22Error loading version from resource %5C%22sdk-version.txt%5C%22: %22 + ex.getMessage());%0A
         %7D%0A%0A 

Add null check and factor error messages.