Giter VIP home page Giter VIP logo

Comments (5)

Octarine-J avatar Octarine-J commented on June 27, 2024 2

This warning is shown when accessing a non-public class from a .java file that contains multiple classes.

Although it's not recommended, it is possible to declare multiple classes in one .java file. However, only one of those classes can be public:

=== A.java ===

public class A {
// ...
}

class B {
// this is an auxiliary class
}

============

from jpf-core.

gayanW avatar gayanW commented on June 27, 2024

The current code expects to have java.lang.CompoundEnumeration public standard Java class. But due to changes in the JDK, there seems to have no such public class. In JDK 9/10 for example it is declared in the java/lang/ClassLoader.java itself.

Please see the PR.

public Enumeration<URL> getResources(String name) throws IOException {
Enumeration<URL>[] resEnum = new Enumeration[2];
if(parent == null) {
resEnum[0] = getSystemClassLoader().getResourcesURL(name);
} else{
resEnum[0] = parent.getResources(name);
}
resEnum[1] = findResources(name);
return new CompoundEnumeration<URL>(resEnum);
}

References:
http://hg.openjdk.java.net/jdk10/jdk10/jdk/rev/47e7d7363249

from jpf-core.

Octarine-J avatar Octarine-J commented on June 27, 2024

It seems that this class is a merely utility that allows continuous iteration over all values from an array of enumerations. The class name is probably not important; the essential part lies in the behaviour. Maybe we can rewrite this method to return an instance of Enumeration that contains all values from the arrays resEnum[0] and resEnum[1]?

By the way, this Enumeration class is from JDK 1.0, and probably is not used widely anymore; its name is a bit unfortunate as one can confuse it with Enum. This Enumeration class seems to be a less poverful equivalent of Iterator.

from jpf-core.

gayanW avatar gayanW commented on June 27, 2024

Thanks for the tip. What about this implementation, though it is quite verbose?

  public Enumeration<URL> getResources(String name) throws IOException {
    Vector<URL> urlVector = new Vector<>(2);
    if(parent == null) {
      Iterator<URL> iterator = getSystemClassLoader().getResourcesURL(name).asIterator();
      while (iterator.hasNext()) {
        urlVector.add(iterator.next());
      }
    } else{
      Iterator<URL> iterator = parent.getResources(name).asIterator();
      while (iterator.hasNext()) {
        urlVector.add(iterator.next());
      }
    }
    Iterator<URL> iterator = findResources(name).asIterator();
    while (iterator.hasNext()) {
      urlVector.add(iterator.next());
    }

    return urlVector.elements();
  }

from jpf-core.

Octarine-J avatar Octarine-J commented on June 27, 2024

Well, using Vector is not recommended for new code (very inefficient), although it conveniently returns an Enumeration. I would add a helper adapter class like the one below, and then used Iterator::forEachRemaining to add elements to a collection such as ArrayList.

    public class EnumerationAdapter<E> implements Enumeration<E> {
        private final Iterator<E> iterator;

        public EnumerationProxy(Collection<E> collection) {
            iterator = collection.iterator();
        }

        @Override
        public boolean hasMoreElements() {
            return iterator.hasNext();
        }

        @Override
        public E nextElement() {
            return iterator.next();
        }
    }

from jpf-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.