Giter Club home page Giter Club logo

cafebabe's People

Contributors

colder avatar manoskouk avatar mhutzli avatar pradeepk avatar psuter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cafebabe's Issues

Sanitize class files

CC: @manoskouk
By adding duplicated methods/fields is possible to generate ill-formed class files without any warnings; failing at runtime with ClassFormatError.
Tracking duplicated methods/fields is a bit hard since methods can change their static-ness; the check should be done on build-time...
I have a slightly more general solution; which consists in loading the class file (without resolving any dependencies) after being generated just to verify it's correctness by ensuring it passes the JVM checks.
Any comments?

ArrayIndexOutOfBoundsException with invalid set of bytecode instructions

Hi,

As asked here is minimal code reproducting the issue :

object App extends App {

  import cafebabe.ByteCodes._
  import cafebabe.AbstractByteCodes._

  val classFile = new cafebabe.ClassFile("HW", None)

  classFile.setSourceFile("HW.java")

  classFile.addDefaultConstructor

  val codeHandler = classFile.addMainMethod.codeHandler

  codeHandler <<
    GetStatic("java/lang/System", "out", "Ljava/io/PrintStream;") <<
    Ldc("Hello world!") <<
    InvokeVirtual("java/io/PrintStream", "println", "(Ljava/lang/String;)V")  /* <<
    RETURN */

  codeHandler.freeze
  classFile.writeToFile("./classfiles/HW.class")
}

As you can see, I deliberately commented the RETURN bytecode.

And here is the stack trace :

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8
    at cafebabe.CodeHandler.setHeight$1(CodeHandler.scala:147)
    at cafebabe.CodeHandler.computeMaxStack(CodeHandler.scala:222)
    at cafebabe.CodeHandler.freeze(CodeHandler.scala:129)
    at App$delayedInit$body.apply(App.scala:22)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App$$anonfun$main$1.apply(App.scala:60)
    at scala.App$$anonfun$main$1.apply(App.scala:60)
    at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
    at scala.collection.immutable.List.foreach(List.scala:76)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:30)
    at scala.App$class.main(App.scala:60)
    at App$.main(App.scala:3)
    at App.main(App.scala)

There of course a lot of other situation where an ArrayIndexOutOfBoundsException is thrown. As soon as some required bytecodes are missing it seems to suffer from this issue.

I'm using scala 2.9.3 with cafebabe 1.2. If you need any more information, let me know.

No "addMethod" for abstract methods with no body

Hi there,

So I noticed you implemented support for interfaces, but you forgot to add a method in ClassFile.scala that adds a method with no code attribute. I locally wrote a method that handles this, called addMethodHead. Maybe you can implement it (or some variation of it) in your source code. The following picture shows the method I added:

image

Have a good one!

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.