Refine search
@SuppressWarnings("unchecked") public Object construct(Node node) { SequenceNode snode = (SequenceNode) node; if (Set.class.isAssignableFrom(node.getType())) { if (node.isTwoStepsConstruction()) { throw new YAMLException("Set cannot be recursive."); } else { return constructSet(snode); } else if (Collection.class.isAssignableFrom(node.getType())) { if (node.isTwoStepsConstruction()) { return newList(snode); } else { return constructSequence(snode); } else if (node.getType().isArray()) { return c.newInstance(argumentList); } catch (Exception e) { throw new YAMLException(e); return c.newInstance(argumentList.toArray()); } catch (Exception e) { throw new YAMLException(e); throw new YAMLException( "No suitable constructor with " + String.valueOf(snode.getValue().size()) + " arguments found for " + node.getType());
public YAMLException(JsonParser p, org.yaml.snakeyaml.error.YAMLException src) { super(p, src.getMessage(), src); }
protected Object constructJavaBean2ndStep(MappingNode node, Object object) { flattenMapping(node); Class<? extends Object> beanType = node.getType(); List<NodeTuple> nodeValue = node.getValue(); throw new YAMLException( "Keys must be scalars but found: " + tuple.getKeyNode()); String key = (String) constructObject(keyNode); try { TypeDescription memberDescription = typeDefinitions.get(beanType); throw new YAMLException("No writable property '" + key + "' on class: " + beanType.getName()); valueNode.setType(property.getType()); final boolean typeDetected = (memberDescription != null) ? memberDescription.setupPropertyType(key, valueNode) : false; if (!typeDetected && valueNode.getNodeId() != NodeId.scalar) { if (valueNode.getNodeId() == NodeId.sequence) { Class<?> t = arguments[0]; SequenceNode snode = (SequenceNode) valueNode; : constructObject(valueNode);
/** * Fail with a reminder to provide the seconds step for a recursive * structure * * @see org.yaml.snakeyaml.constructor.Construct#construct2ndStep(org.yaml.snakeyaml.nodes.Node, * java.lang.Object) */ public void construct2ndStep(Node node, Object data) { if (node.isTwoStepsConstruction()) { throw new IllegalStateException("Not Implemented in " + getClass().getName()); } else { throw new YAMLException("Unexpected recursive structure for Node: " + node); } } }
if (Properties.class.isAssignableFrom(node.getType())) { Properties properties = new Properties(); if (!node.isTwoStepsConstruction()) { constructMapping2ndStep(mnode, properties); } else { throw new YAMLException("Properties must not be recursive."); } else if (SortedMap.class.isAssignableFrom(node.getType())) { SortedMap<Object, Object> map = new TreeMap<Object, Object>(); if (!node.isTwoStepsConstruction()) { constructMapping2ndStep(mnode, map); } else if (Map.class.isAssignableFrom(node.getType())) { if (node.isTwoStepsConstruction()) { return createDefaultMap(); } else { return constructMapping(mnode);
@Override public Node resolve(Node node, ResourceLoader resourceLoader, NodeHandler nodeHandler) { String className = ((ScalarNode) node).getValue(); try { Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(className); JAXBContext context = JAXBContext.newInstance(clazz); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); context.generateSchema(new SchemaOutputResolver() { @Override public Result createOutput(String namespaceURI, String suggestedFileName) throws IOException { StreamResult result = new StreamResult(baos); result.setSystemId("001"); return result; } }); String schema = baos.toString(); return new ScalarNode(Tag.STR, schema, node.getStartMark(), node.getEndMark(), ((ScalarNode) node).getStyle()); } catch (Exception e) { throw new YAMLException(e); } }
public void setIndicatorIndent(int indicatorIndent) { if (indicatorIndent < 0) { throw new YAMLException("Indicator indent must be non-negative."); } if (indicatorIndent > Emitter.MAX_INDENT - 1) { throw new YAMLException("Indicator indent must be at most Emitter.MAX_INDENT-1: " + (Emitter.MAX_INDENT - 1)); } this.indicatorIndent = indicatorIndent; }
protected Class<?> getClassForNode(Node node) { Class<? extends Object> classForTag = typeTags.get(node.getTag()); if (classForTag == null) { String name = node.getTag().getClassName(); Class<?> cl; try { cl = getClassForName(name); } catch (ClassNotFoundException e) { throw new YAMLException("Class not found: " + name); } typeTags.put(node.getTag(), cl); return cl; } else { return classForTag; } }
@NotNull public static CDepManifestYml convertStringToManifest(@NotNull String url, @NotNull String content) { Invariant.registerYamlFile(url); Yaml yaml = new Yaml(new Constructor(CDepManifestYml.class)); CDepManifestYml manifest; byte[] bytes = content.getBytes(StandardCharsets.UTF_8); try { manifest = (CDepManifestYml) yaml.load(new ByteArrayInputStream(bytes)); // Try to read current version if (manifest != null) { manifest.sourceVersion = CDepManifestYmlVersion.vlatest; } } catch (YAMLException e) { try { manifest = V3Reader.convertStringToManifest(content); } catch (YAMLException e2) { if (!tryCreateSensibleParseError(e, 0)) { // If older readers also couldn't read it then report the original exception. require(false, e.toString()); } return new CDepManifestYml(EMPTY_COORDINATE); } } require(manifest != null, "Manifest was empty"); assert manifest != null; manifest = new ConvertNullToDefaultRewriter().visitCDepManifestYml(manifest); Node nodes = yaml.compose(new InputStreamReader(new ByteArrayInputStream(bytes))); SnakeYmlUtils.mapAndRegisterNodes(url, manifest, nodes); return manifest; }
@SuppressWarnings("unchecked") public void construct2ndStep(Node node, Object object) { SequenceNode snode = (SequenceNode) node; if (List.class.isAssignableFrom(node.getType())) { List<Object> list = (List<Object>) object; constructSequenceStep2(snode, list); } else if (node.getType().isArray()) { constructArrayStep2(snode, object); } else { throw new YAMLException("Immutable objects cannot be recursive."); } } }
public Config loadConfig(URL url) throws ConfigurationException { try { logger.debug("Loading settings from {}", url); byte[] configBytes; try (InputStream is = url.openStream()) { configBytes = ByteStreams.toByteArray(is); } catch (IOException e) { // getStorageConfigURL should have ruled this out throw new AssertionError(e); } Constructor constructor = new CustomConstructor(Config.class); PropertiesChecker propertiesChecker = new PropertiesChecker(); constructor.setPropertyUtils(propertiesChecker); Yaml yaml = new Yaml(constructor); Config result = loadConfig(yaml, configBytes); propertiesChecker.check(); return result; } catch (YAMLException e) { throw new ConfigurationException("Invalid yaml: " + url + SystemUtils.LINE_SEPARATOR + " Error: " + e.getMessage(), false); } }
for (Node child : node.getValue()) { if (child.getType() == Object.class) { child.setType(componentType); throw new YAMLException("unexpected primitive type");
if (root != null && root.getNodeId() == mapping) errorMessage.add(createErrorResult(ex.getMessage()));
protected Object newInstance(Class<?> ancestor, Node node, boolean tryDefault) throws InstantiationException { final Class<? extends Object> type = node.getType(); if (typeDefinitions.containsKey(type)) { TypeDescription td = typeDefinitions.get(type); final Object instance = td.newInstance(node); if (instance != null) { return instance; } } if (tryDefault) { /* * Removed <code> have InstantiationException in case of abstract * type */ if (ancestor.isAssignableFrom(type) && !Modifier.isAbstract(type.getModifiers())) { try { java.lang.reflect.Constructor<?> c = type.getDeclaredConstructor(); c.setAccessible(true); return c.newInstance(); } catch (NoSuchMethodException e) { throw new InstantiationException("NoSuchMethodException:" + e.getLocalizedMessage()); } catch (Exception e) { throw new YAMLException(e); } } } throw new InstantiationException(); }
public static void dumpFromAst(Node rootNode, Writer output) { if (rootNode == null) { throw new IllegalArgumentException("rootNode is null"); } DumperOptions dumperOptions = new DumperOptions(); //HYBRIS start - replaced null param with rootTag Tag rootTag = rootNode.getTag(); Serializer serializer = new Serializer(new Emitter(output, dumperOptions), new Resolver(), dumperOptions, rootTag); //HYBRIS end try { serializer.open(); serializer.serialize(rootNode); serializer.close(); } catch (IOException e) { throw new YAMLException(e); } }
return newInstance(type, node, false); } catch (InstantiationException e1) { if (javaConstructor == null) { try { return newInstance(type, node, false); } catch (InstantiationException ie) { throw new YAMLException("No single argument constructor found for " + type + " : " + ie.getMessage()); argument = constructScalar(node); try { javaConstructor = type.getDeclaredConstructor(String.class); } catch (Exception e) { throw new YAMLException("Can't construct a java object for scalar " + node.getTag() + "; No String constructor found. Exception=" + e.getMessage(), e);
throw new YAMLException("No single argument constructor found for " + type); } else if (oneArgCount == 1) { argument = constructStandardJavaInstance( argument = constructScalar(node); try { javaConstructor = type.getDeclaredConstructor(String.class); } catch (Exception e) { throw new YAMLException("Can't construct a java object for scalar " + node.getTag() + "; No String constructor found. Exception=" + e.getMessage(), e);
private static boolean tryCreateSensibleParseError(YAMLException e, int depth) { if (depth > 20) { return false; } if (e != null) { if (e.getCause() == null) { if (e.getMessage().contains("Unable to find property 'lib'")) { require(false, "Could not parse manifest. " + "The field 'lib' could not be created. Should it be 'libs'?"); return true; } } else { return tryCreateSensibleParseError((YAMLException) e.getCause(), depth + 1); } } return false; }
ye.fillInStackTrace(); if (ProjectUsageIntegrityPlugin.getInstance().isShowAdvancedInformationProperty()) { final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); ye.printStackTrace(pw); buff.append(sw.toString());
YEditLog.logger.info( "Encountered YAML syntax error:" + ex.toString() );