mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
WEB-20519 JSON schema: non-string element in required section hangs IDE
This commit is contained in:
@@ -411,6 +411,8 @@ public class JsonSchemaReader {
|
||||
while (in.peek() != JsonToken.END_ARRAY) {
|
||||
if (in.peek() == JsonToken.STRING) {
|
||||
required.add(in.nextString());
|
||||
} else {
|
||||
in.skipValue();
|
||||
}
|
||||
}
|
||||
in.endArray();
|
||||
@@ -479,7 +481,7 @@ public class JsonSchemaReader {
|
||||
while (in.peek() != JsonToken.END_ARRAY) {
|
||||
if (in.peek() == JsonToken.BEGIN_OBJECT) {
|
||||
list.add(readInnerObject(in));
|
||||
}
|
||||
} else in.skipValue();
|
||||
}
|
||||
in.endArray();
|
||||
object.setItemsSchemaList(list);
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
package com.jetbrains.jsonSchema.impl;
|
||||
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.util.concurrency.Semaphore;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* @author Irina.Chernushina on 8/29/2015.
|
||||
@@ -60,4 +65,41 @@ public class JsonSchemaReadTest {
|
||||
final JsonSchemaObject read = reader.read(new FileReader(file));
|
||||
Assert.assertTrue(read.getDefinitions().get("common").getProperties().containsKey("id"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadSchemaWithWrongRequired() throws Exception {
|
||||
testSchemaReadNotHung(new File(PlatformTestUtil.getCommunityPath(), "json/tests/testData/jsonSchema/withWrongRequired.json"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadSchemaWithWrongItems() throws Exception {
|
||||
testSchemaReadNotHung(new File(PlatformTestUtil.getCommunityPath(), "json/tests/testData/jsonSchema/withWrongItems.json"));
|
||||
}
|
||||
|
||||
private static void testSchemaReadNotHung(final File file) throws IOException {
|
||||
Assert.assertTrue(file.exists());
|
||||
|
||||
final AtomicBoolean done = new AtomicBoolean();
|
||||
final AtomicReference<IOException> error = new AtomicReference<>();
|
||||
final Semaphore semaphore = new Semaphore();
|
||||
semaphore.down();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final JsonSchemaReader reader = new JsonSchemaReader();
|
||||
try {
|
||||
reader.read(new FileReader(file));
|
||||
done.set(true);
|
||||
}
|
||||
catch (IOException e) {
|
||||
error.set(e);
|
||||
} finally {
|
||||
semaphore.up();
|
||||
}
|
||||
}
|
||||
}, "read test json schema " + file.getName()).start();
|
||||
semaphore.waitFor(TimeUnit.SECONDS.toMillis(60));
|
||||
if (error.get() != null) throw error.get();
|
||||
Assert.assertTrue("Reading test schema hung!", done.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"properties": {
|
||||
"a": {
|
||||
"items": [
|
||||
1
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"required": [{}]
|
||||
}
|
||||
Reference in New Issue
Block a user