diff --git a/htroot/Table_API_p.java b/htroot/Table_API_p.java index d384932a3..19bb52472 100644 --- a/htroot/Table_API_p.java +++ b/htroot/Table_API_p.java @@ -72,9 +72,11 @@ public class Table_API_p { for (String pk: pks) { try { Tables.Row row = sb.tables.select(WorkTables.TABLE_API_NAME, pk.getBytes()); - String url = "http://localhost:" + sb.getConfig("port", "8080") + new String(row.from(WorkTables.TABLE_API_COL_URL)); - result = client.GET(url); - l.put(url, result.getStatusCode()); + if (row != null) { + String url = "http://localhost:" + sb.getConfig("port", "8080") + new String(row.from(WorkTables.TABLE_API_COL_URL)); + result = client.GET(url); + l.put(url, result.getStatusCode()); + } } catch (IOException e) { Log.logException(e); } diff --git a/htroot/Tables_p.java b/htroot/Tables_p.java index 0d7e77401..70ba9f384 100644 --- a/htroot/Tables_p.java +++ b/htroot/Tables_p.java @@ -178,6 +178,7 @@ public class Tables_p { prop.put("showedit_table", table); prop.put("showedit_pk", pk); Tables.Row row = sb.tables.select(table, pk.getBytes()); + if (row == null) return; int count = 0; byte[] cell; for (String col: columns) { diff --git a/source/de/anomic/data/WorkTables.java b/source/de/anomic/data/WorkTables.java index a1280f811..4420ea2bc 100644 --- a/source/de/anomic/data/WorkTables.java +++ b/source/de/anomic/data/WorkTables.java @@ -64,8 +64,6 @@ public class WorkTables extends Tables { ); } catch (IOException e) { Log.logException(e); - } catch (NullPointerException e) { - Log.logException(e); } Log.logInfo("APICALL", apiurl); } diff --git a/source/net/yacy/kelondro/blob/Tables.java b/source/net/yacy/kelondro/blob/Tables.java index 1574f48f2..9e4dac9f3 100644 --- a/source/net/yacy/kelondro/blob/Tables.java +++ b/source/net/yacy/kelondro/blob/Tables.java @@ -130,7 +130,13 @@ public class Tables { } private byte[] ukey(String tablename) throws IOException { - byte[] pk = select(system_table_pkcounter, tablename.getBytes()).from(system_table_pkcounter_counterName); + Row row = select(system_table_pkcounter, tablename.getBytes()); + if (row == null) { + // table counter entry in pkcounter table does not exist: make a new table entry + row = new Row(tablename.getBytes(), system_table_pkcounter_counterName, int2key(0).getBytes()); + insert(system_table_pkcounter, row); + } + byte[] pk = row.from(system_table_pkcounter_counterName); int pki; if (pk == null) { pki = size(tablename); @@ -305,7 +311,8 @@ public class Tables { public Row select(final String table, byte[] pk) throws IOException { BEncodedHeap heap = getHeap(table); - return new Row(pk, heap.get(pk)); + if (heap.has(pk)) return new Row(pk, heap.get(pk)); + return null; } public void delete(final String table, byte[] pk) throws IOException { @@ -403,11 +410,25 @@ public class Tables { final Map map; public Row(final Map.Entry> entry) { + assert entry != null; + assert entry.getKey() != null; + assert entry.getValue() != null; this.pk = entry.getKey(); this.map = entry.getValue(); } public Row(final byte[] pk, final Map map) { + assert pk != null; + assert map != null; + this.pk = pk; + this.map = map; + } + + public Row(final byte[] pk, String k0, byte[] v0) { + assert k0 != null; + assert v0 != null; + HashMap map = new HashMap(); + map.put(k0, v0); this.pk = pk; this.map = map; }