Class Visibility ErrorsSlide 1. Class Visibility Errors Bryan Atsatt February 2009.

Slides:



Advertisements
Similar presentations
Reconciling OO and Haskell-Style Overloading Mark Shields Simon Peyton Jones Microsoft Research Cambridge
Advertisements

Compilation 2011 Static Analysis Johnni Winther Michael I. Schwartzbach Aarhus University.
CSE 331 SOFTWARE DESIGN & IMPLEMENTATION DEBUGGING Autumn 2011 Bug-Date: Sept 9, 1947.
Annoucements  Next labs 9 and 10 are paired for everyone. So don’t miss the lab.  There is a review session for the quiz on Monday, November 4, at 8:00.
Kapsalakis Giorgos - AM: 1959 HY459 - Internet Measurements Fall 2010.
1 Software Processes Name:Wassim Jamal Salem ID: Name:m3taz El Dweak ID:
Do you really get class loaders? Jevgeni Kabanov Founder & CTO of ZeroTurnaround.
(1) ICS 313: Programming Language Theory Chapter 10: Implementing Subprograms.
CS 211 Inheritance AAA.
API Design CPSC 315 – Programming Studio Fall 2008 Follows Kernighan and Pike, The Practice of Programming and Joshua Bloch’s Library-Centric Software.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Object-Oriented.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Exceptions in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Winter 2004/5Pls – inductive – Catriel Beeri1 Inductive Definitions (our meta-language for specifications)  Examples  Syntax  Semantics  Proof Trees.
Chapter 14 Generics and the ArrayList Class Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
1 Computer Systems & Architecture Lesson 1 1. The Architecture Business Cycle.
Spring Dynamic Modules. Startlocation: Documentation: /1.2.1/reference/html/
Fundamentals of Python: From First Programs Through Data Structures
Inheritance. Types of Inheritance Implementation inheritance means that a type derives from a base type, taking all the base type’s member fields and.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
1 Chapter Eight Exception Handling. 2 Objectives Learn about exceptions and the Exception class How to purposely generate a SystemException Learn about.
Called as the Interval Scheduling Problem. A simpler version of a class of scheduling problems. – Can add weights. – Can add multiple resources – Can ask.
1/151/15 ENT Metamodel Implementation & Applications ENT metamodel, prototype implementation Component substitutability checking, ENT based component comparison.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
ESO - Garching 23 June – 02 July, 2003 ACS Course Data entities and XML serialization H. Sommer.
1 Debugging and Testing Overview Defensive Programming The goal is to prevent failures Debugging The goal is to find cause of failures and fix it Testing.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
Review: OSGi – a component framework for Java Bundle OSGi Framework Bundle Java Runtime Environment (JRE) Operating System (OS) Hardware “Dynamic Modules.
Creational Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
The Procedure Abstraction, Part VI: Inheritance in OOLs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled.
Object Oriented Programming with C++/ Session 6 / 1 of 44 Multiple Inheritance and Polymorphism Session 6.
CSSE501 Object-Oriented Development. Chapter 12: Implications of Substitution  In this chapter we will investigate some of the implications of the principle.
Comparing JavaBeans and OSGi Towards an Integration of Two Complementary Component Models HUMBERTO CERVANTES JEAN-MARIE FAVRE 09/02.
OSGi Enablement for Tuscany Raymond Feng. Overview.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
CSCI 383 Object-Oriented Programming & Design Lecture 17 Martin van Bommel.
From Quality Control to Quality Assurance…and Beyond Alan Page Microsoft.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Test Coverage CS-300 Fall 2005 Supreeth Venkataraman.
Review of Software Process Models Review Class 1 Software Process Models CEN 4021 Class 2 – 01/12.
CS 211: Computer Architecture Lecture 6 Module 2 Exploiting Instruction Level Parallelism with Software Approaches Instructor: Morris Lancaster.
Programming in Java CSCI-2220 Object Oriented Programming.
Implementing Subprograms What actions must take place when subprograms are called and when they terminate? –calling a subprogram has several associated.
Abstract Classes and Interfaces 5-Dec-15. Abstract methods You can declare an object without defining it: Person p; Similarly, you can declare a method.
Garbage Collection and Classloading Java Garbage Collectors  Eden Space  Surviver Space  Tenured Gen  Perm Gen  Garbage Collection Notes Classloading.
Interfaces About Interfaces Interfaces and abstract classes provide more structured way to separate interface from implementation
Software Engineering1  Verification: The software should conform to its specification  Validation: The software should do what the user really requires.
School of Computer Science & Information Technology G6DICP - Lecture 6 Errors, bugs and debugging.
® IBM Software Group © 2009 IBM Corporation Essentials of Modeling with the IBM Rational Software Architect, V7.5 Module 15: Traceability and Static Analysis.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Version Control and SVN ECE 297. Why Do We Need Version Control?
Object-Oriented Design Concepts University of Sunderland.
Recap Introduction to Inheritance Inheritance in C++ IS-A Relationship Polymorphism in Inheritance Classes in Inheritance Visibility Rules Constructor.
CSCI-383 Object-Oriented Programming & Design Lecture 17.
UNIT-IV Designing Classes – Access Layer ‐ Object Storage ‐ Object Interoperability.
Modern Programming Tools And Techniques-I
Chapter 11 Object-Oriented Design
Generics, Lambdas, Reflections
Phil Tayco Slide version 1.0 Created Oct 2, 2017
Statistical Reasoning December 8, 2015 Chapter 6.2
Chapter 4: Designing Studies
Multilevel Mission Coordination for Coalition Operations
Generics, Lambdas and Reflection
Plug-In Architecture Pattern
Presentation transcript:

Class Visibility ErrorsSlide 1

Class Visibility Errors Bryan Atsatt February 2009

Class Visibility ErrorsSlide 3 Class Visibility Errors Not Enough Visibility (not-found) ClassNotFoundException NoClassDefFoundError Split Visibility (split-packages) IllegalAccessError (package-private, different loaders) Too Much Visibility (duplicates) LinkageError (loader constraint violation) ClassCastException (same name, different loaders) Most developers have not seen duplicate errors… yet.

Class Visibility ErrorsSlide 4 Duplicate Class Definitions Ticking time bombs A duplicate exists when there are two or more Class instances with the same name Duplicates always have different defining loaders Frequently result in runtime errors LinkageError The JVM enforces "Loading Constraints" (5.3.4) to avoid collisions: "It is essential that any type name N mentioned in the field or method descriptor denote the same class or interface when loaded by L1 and when loaded by L2.“ ClassCastException Well known in the wild (e.g."child-first“ loading from Servlet specification, OSGi). Very confusing since type names are same. Cause and effect widely separated in time.

Class Visibility ErrorsSlide 5 Duplication Errors Oracle’s experience (>= 2003) Modules (“shared-libraries”) in application server Named, versioned loader instances Versioned imports  complex (acyclic) graph Rich reflective api and diagnostic machinery Highly successful at solving the versioning problem, but… Duplication errors suddenly common No prevention model in place Fancy diagnostics and education averted disaster

Class Visibility ErrorsSlide 6 Duplication Errors A support nightmare Subtle conditions, which few developers understand Class loading is like plumbing: ignored until it breaks, messy when it does and often requiring special expertise to fix Extremely hard to diagnose Error messages rarely contain enough information Loading often deferred until first use, stack trace confusing Loading can be highly recursive, stack often very deep Stack trace does not provide instance data, cannot determine which loader(s) are involved No useful reflective api on ClassLoader Most loader code pathways are non-debug or native so mostly useless in a debugger

Class Visibility ErrorsSlide 7 How Are Duplicates Created? Today Copies of jars in different loaders EE implementations that support child-first Poorly behaved custom loaders Tomorrow Multiple versions of a module Copies of classes in a module that are available in another Wrong import choice when multiple candidates are available

Class Visibility ErrorsSlide 8 Modules Change The Balance Modules should reduce frequency of not-found errors at runtime, but... Will increase frequency of them at compile time, initially, since dependency declarations must be precise. Tools can certainly help. Without intervention, modules will significantly increase frequency of duplication errors at runtime.

Class Visibility ErrorsSlide 9 Modules == More Loaders More loaders == more opportunities for duplicates Finer grained class partitioning A small, simple tree of loaders becomes a potentially large (even cyclic) graph. Tendency to bundle classes defensively or for convenience Multiple simultaneous module versions Unsophisticated use of version requirements Compiler can catch many error cases, but only for a specific environment.

Class Visibility ErrorsSlide 10 Error Cases Conflicting imports, one module These cases use an example “animal” module system, with a simple property syntax. Multiple versions of “akita” are present in the repository. pika: Module-Imports=akita, version=1.0; newt; akita, version=0.9 Module “pika” imports module “akita” twice, “newt” once; silly, but possible. If not prevented, duplicates from akita will be visible to pika. See AnimalModuleTest.conflictingImportsFail()

Class Visibility ErrorsSlide 11 Error Cases Conflicting module imports == LinkageError vole: Module-Imports=akita, version=0.9 wombat: Module-Imports=vole; akita Vole ctor takes Akita : public Vole(Akita akita) Wombat instantiates Vole : new Vole(new Akita()); See AnimalModuleTest.moduleImportsCauseLinkageError()

Class Visibility ErrorsSlide 12 Error Cases Conflicting package imports == LinkageError raven: Imports=akita, version=0.9 shrew: Imports=raven; akita Raven ctor takes Akita : public Raven(Akita akita) Shrew instantiates Raven : new Raven(new Akita()); See AnimalModuleTest.packageImportsCauseLinkageError()

Class Visibility ErrorsSlide 13 Error Cases Conflicting imports == ClassCastException newt: Module-Imports=akita, version=0.5 oryx: Module-Imports=akita; newt Newt ctor publishes Akita instance to static List. Oryx.toString() tries to return loader name for instance in static list. Unspecified version in oryx selects newer version. Compiler generated downcast to Akita in Oryx fails. The same modules do not fail when only the 0.5 version of akita is present. See AnimalModuleTest.moduleImportsCauseClassCast() and AnimalModuleTest.moduleImportsDoNotCauseClassCast()

Class Visibility ErrorsSlide 14 Error Cases Embedded copy == ClassCastException newt: Module-Imports=akita, version=0.5 quetzal: Imports=newt Quetzal contains a copy of classes from akita, same generics downcast results in error when it tries to reference Akita instance from the list in newt. See AnimalModuleTest.embeddedCopyCausesClassCast()

Class Visibility ErrorsSlide 15 Duplicates Acceptable if Not Shared If C does not expose classes from B2, either by re- exporting them or by sharing instances, then A ‘s import of C will not result in failures. Duplicates that are hidden implementation details are fine. If not allowed, A is forced to move to B2, or to find a version of C that does not conflict, neither of which is required here; in a complex system, this behavior would be a serious usability issue. x  y == x imports y

Class Visibility ErrorsSlide 16 So… rule out all visible duplicates? Maybe, but first, to detect them, we need to be able to determine what classes or packages are "exposed" by each module. So assume that we can at least ask each module what packages it exports. Now, we can collect transitive dependencies, discover all exported packages, and ensure that modules share a common provider where packages intersect.

Class Visibility ErrorsSlide 17 But… We Can Do Better If package level imports are possible (ever), then we want a slight refinement. Given that a single module will likely export many packages, an importer may select a subset of them; if classes from that subset don’t expose the duplicate, that importer is shielded from errors. If C exports packages x, y and z, and only y refers to classes from B, then importers of x or z don't care about the duplicate.

Class Visibility ErrorsSlide 18 Maximize Resolution Flexibility Implied dependencies To support this refinement, we need to know what package imports are “implied” by a given package export. That is, if an exported class uses a class from another package (e.g. in a method signature), as long as we can determine that fact at runtime, we can enforce the no duplicates rule. And we enforce it at a granularity that maximizes resolution flexibility.

Class Visibility ErrorsSlide 19 Error Avoided Identical scenario as raven & shrew, but declare 'implied' dependency: toad: Exports=toad, depends=akita Imports=akita, version=0.9 uakari: Imports=toad; akita Toad ctor takes Akita: public Toad(Akita akita) Uakari instantiates Toad: new Toad(new Akita()); System ensures that toad and uakari both select akita 0.9. See AnimalModuleTest.packageImportsAndDependsDoesNotCauseLinkageError()

Class Visibility ErrorsSlide 20 Summary Many failures occur only when multiple versions are present and will therefore manifest very late in the cycle. Duplication is a double-edged sword: Useful to avoid forced split of dependency graph when duplicates are hidden implementation details. Dangerous when duplicate types are surfaced. Implied dependency declarations enable disambiguation.

Class Visibility ErrorsSlide 21 Summary, continued. Early detection is critical to avoid support nightmare: compile time (one "model" environment) resolution time (actual environment) Enumeration of package level exports is required for duplicate detection and warning/failure at resolution time. Class space "consistency" model is required, but enforcement must be controlled declaratively; tools should generate this information.

Class Visibility ErrorsSlide 22 Resolution Constraints 1.A module must fail to resolve if a required import cannot be satisfied. 2.A failed module must not be used to satisfy imports. 3.Importing a module M is equivalent to importing all packages exported by M. 4.A module may declare that it both exports and imports package p ; once resolved it may either export or import p, not both. 5.If multiple providers exist for an import, resolved providers are preferred over unresolved, and higher versions over lower. 6.Modules that share a dependency must select a common provider or fail; a shared dependency on package s exists between modules M 1 and M 2 when all of the following are true: M 1 imports package p from M 2 Package p depends on package s M 1 either imports or exports package s

Class Visibility ErrorsSlide 23 Appendix OSGi ‘uses’ example from R4 specification Given A: Import-Package: q; version=”[1.0,1.0]” Export-Package: p; uses:=”q,r” B: Export-Package: q; version=1.0 C: Export-Package: q; version=2.0 Shared dependency on q means D fails to resolve D: Import-Package: p, q; version=2.0

Class Visibility ErrorsSlide 24