Repository: jenkinsci/jenkins
File: core/src/main/java/hudson/model/View.java (Java)

Code before:
                throw new Failure("No such view: " + from);
        }
        String xml = Jenkins.XSTREAM.toXML(src);
        v = createViewFromXML(name, new ByteArrayInputStream(xml.getBytes(Charset.defaultCharset())));
        return v;
    }

    /**
     * Instantiate View subtype from XML stream.
     *
     * @param name Alternative name to use or {@code null} to keep the one in xml.
     */
    public static View createViewFromXML(String name, InputStream xml) throws IOException {

        try (InputStream in = new BufferedInputStream(xml)) {
            View v = (View) Jenkins.XSTREAM.fromXML(in);
            if (name != null) v.name = name;
            Jenkins.checkGoodName(v.name);
            return v;
        } catch (StreamException | ConversionException | Error e) { // mostly reflection errors
            throw new IOException("Unable to read", e);
        }
    }

    // for Jelly
    @Restricted(NoExternalUse.class)
    public boolean isMyViewsProperty() {
        return getOwner() instanceof MyViewsProperty;
    }

    public static class PropertyList extends DescribableList<ViewProperty, ViewPropertyDescriptor> {
        private PropertyList(View owner) {
            super(owner);
        }

        public PropertyList() {// needed for XStream deserialization
        }

        public View getOwner() {
            return (View) owner;
        }

        @Override
        protected void onModified() throws IOException {
            for (ViewProperty p : this)
                p.setView(getOwner());
        }
    }

    /**
     * "Job" in "New Job". When a view is used in a context that restricts the child type,

Review comment (suggestion):
or `DoNotUse` (restrictions are only enforced on Java calls)

Code after:
        }
        String xml = Jenkins.XSTREAM.toXML(src);
        v = createViewFromXML(name, new ByteArrayInputStream(xml.getBytes(Charset.defaultCharset())));
        return v;
    }

    /**
     * Instantiate View subtype from XML stream.
     *
     * @param name Alternative name to use or {@code null} to keep the one in xml.
     */
    public static View createViewFromXML(String name, InputStream xml) throws IOException {

        try (InputStream in = new BufferedInputStream(xml)) {
            View v = (View) Jenkins.XSTREAM.fromXML(in);
            if (name != null) v.name = name;
            Jenkins.checkGoodName(v.name);
            return v;
        } catch (StreamException | ConversionException | Error e) { // mostly reflection errors
            throw new IOException("Unable to read", e);
        }
    }

    // for Jelly
    @Restricted(DoNotUse.class)
    public boolean isMyViewsProperty() {
        return getOwner() instanceof MyViewsProperty;
    }

    public static class PropertyList extends DescribableList<ViewProperty, ViewPropertyDescriptor> {
        private PropertyList(View owner) {
            super(owner);
        }

        public PropertyList() {// needed for XStream deserialization
        }

        public View getOwner() {
            return (View) owner;
        }

        @Override
        protected void onModified() throws IOException {
            for (ViewProperty p : this)
                p.setView(getOwner());
        }
    }

    /**
     * "Job" in "New Job". When a view is used in a context that restricts the child type,
     * It might be useful to override this.